Reputation: 460
I have written a listen python udp code to receive a stream which the output should numbers of 1 to 42, however, the output seems to be 42 symbols instead of values(as such):
1450472711.51 : @ 4@ @P@ $@ @ @ @ @ @ "@ $@ &@ (@ *@ ,@ .@ 0@ 1@ 2@ 3@ 4@ 5@ 6@ 7@ 8@ 9@ :@ ;@ <@ =@ >@ ?@ @@ �@@ A@ �A@ B@ �B@ C@ �C@ D@ �D@
Here is the code: I sniffed the packets and they seems to all be 378 packets long and this continues to happen, so i dont see any packet drop.
import socket,sys, ast , os
from time import ctime
import time
print >> sys.stderr, os.getcwd()
print >> sys.stderr , ctime()
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
ip = '192.168.10.101'
port = 25000
server_address = (ip, port)
sock.bind(server_address) # bind socket
sock.settimeout(2) # sock configuration
sock.setblocking(1)
print >> sys.stderr, 'able to bind'
i = 0
client = ''
byte = 378
while True:
if i == 0:
print >> sys.stderr, 'connected'
data,client = sock.recvfrom(byte)
print >> sys.stderr,time.time() ,":",data , "\n"
i= i+1
Anyone able to explain why this is? is there some conversion I am not doing when the packets are received ?
thank you !
Upvotes: 1
Views: 166
Reputation: 2242
You are printing a string of binary data. To see the actual binary (bytewise) numbers that are transmitted, try something like:
for c in data:
print ord(c)
Upvotes: 1