TAGS :Viewed: 4 - Published at: a few seconds ago

[ Python Socket Receiving Doubles ]

I need a python program to use a TCP connection(to another program) to retrieve sets of 9 bytes.

The first of the nine bytes represents a char, and the rest represent a double.

How can I extract this information from a python socket? Will I have to do the maths manually to convert the stream data or is there a better way?

Answer 1


Take a look at python struct

http://docs.python.org/library/struct.html

So something like

from struct import unpack

unpack('cd',socket_read_buffer)

--> ('c', 3.1415)

Be careful of Endianness.