Yes I know UDP is bad but unfortunately I have no choice - my server only takes UDP...
What I have is a list that contains hex values, need to send that out UDP.
If I try and send the list I get - 'TypeError: must be string or buffer, not list'
If i convert to a string (called aList in my code) I get - 'TypeError: an integer is required' Print of aList = 09004000e3f00005f5
if I convert aList to an int with base 16 I get - 'TypeError: must be string or buffer, not long'
Suspect it's something basic but I'm missing it.
Simple code looks like::
import socket #for sockets
UDP_PORT = 21105;
UDP_HOST = '10.194.34.151';
z21 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
def _getLocoInfo (id):
arr = [ 0x09, 0x00, 0x40, 0x00, 0xE3, 0xF0, 0x00, id]
arr.append(arr[5]^arr[6]^arr[7])
return arr
msg = _getLocoInfo(0x05)
aList = "".join("%02x" % b for b in msg)
print (a)
try :
z21.send(msg ,(UDP_HOST, UDP_PORT) )
# receive data from client (data, addr)
d = s.recvfrom(1024)
print ('Server reply : ' + reply)
except socket.error as e:
print ('Error Code : ' + str(e[0]) + ' Message ' + e[1])
sys.exit()