from binascii import b2a_hex
from binascii import a2b_hex
from socket import *
from struct import pack
s = socket(AF_INET, SOCK_DGRAM)


# Following line 'list\0\0\0\0,ifff\0\0\0' with correct length
listhead = a2b_hex('6c697374000000002c69666666000000')
# Following is packed values for ifff, different each time.
listtail = pack('>ifff',3,0.25,0.75,0.99)

# Concatenate & send:
binlist = listhead + listtail
s.sendto(binlist,("localhost",7401))




s.bind(("",10000))
>>> data, address = s.recvfrom(1024)
>>> hex = b2a_hex(data)
>>> print "|", data, "|"
| list    ,iiii              |
>>> print hex
6c697374000000002c696969690000000000000c00000000ffffffff00000003
>>> s.sento(msg,("localhost",7401))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: '_socketobject' object has no attribute 'sento'
>>> s.sendto(msg,("localhost",7401))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'msg' is not defined
>>> s.sendto(data,("localhost",7401))
32
>>> s.sendto(data,("localhost",7401))
32
>>> s.sendto(a2b_hex('6c697374000000002c696969690000000000000c00000000fffffffe00
000004',("localhost",7401))
...
... )
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: a2b_hex() takes exactly 1 argument (2 given)
>>> s.sendto(a2b_hex('6c697374000000002c696969690000000000000c00000000fffffffe00
000004'),("localhost",7401))
32
>>> data, address = s.recvfrom(1024)
>>> hex = b2a_hex(data)
>>> print "|", data, "|"
| list    ,ifff      ?         |
>>> print hex
6c697374000000002c69666666000000000000013f800000bf80000000000000
>>> ^Z

