Python Forum
Decode data of udp connection
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Decode data of udp connection
#1
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?
Reply
#2
I tried using:
str.decode("utf-8", "strict")
to no avail.
I beleive that what you have is pure binary data, not encoded text.
Reply
#3
(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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020