Python Forum
Decode data of udp connection - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: Decode data of udp connection (/thread-5841.html)



Decode data of udp connection - deividnastri - Oct-24-2017

Hi, i am receiving data from a UDP connection and don't know how decode this.

Code where i receive the data:

import socket

# Set up a UDP server
UDPSock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
listen_addr = ("", 6501)
UDPSock.bind(listen_addr)

while True:
    data,addr = UDPSock.recvfrom(1024)
    print("Bytes: ",len(data))
    print("A: ", data)
    print("B: ", repr(data))
The data received:

Output:
Bytes: 62 A: b'\xa5rI\x97\xf7\xad~j\xb1\x13\xbc\x98z\xe8^w\xf9\xb7nl3\xf8kozn\x9bK\xb3$\x86oz\xde\x9b\xa2\xb3\xbd`7zp"z\xb1\xd7}oyn\x9a\x8c\xb8\x9f\x14"\x17\x1d\x9b\x8c\x1b8' B: b'\xa5rI\x97\xf7\xad~j\xb1\x13\xbc\x98z\xe8^w\xf9\xb7nl3\xf8kozn\x9bK\xb3$\x86oz\xde\x9b\xa2\xb3\xbd`7zp"z\xb1\xd7}oyn\x9a\x8c\xb8\x9f\x14"\x17\x1d\x9b\x8c\x1b8'
I try use codecs.decode, struct with no sucess.
Can anyone help me?


RE: Decode data of udp connection - Larz60+ - Oct-24-2017

I tried using:
str.decode("utf-8", "strict")
to no avail.
I beleive that what you have is pure binary data, not encoded text.


RE: Decode data of udp connection - deividnastri - Oct-24-2017

(Oct-24-2017, 05:04 PM)Larz60+ Wrote: I tried using:
str.decode("utf-8", "strict")
to no avail.
I beleive that what you have is pure binary data, not encoded text.

Hi Larz60, tks for ur time.

I try that to, but no sucess. Will try with binary.