prob with struct and byte order

nephish at xit.net nephish at xit.net
Mon Jul 24 12:30:30 EDT 2006


hello there, all.

i have a difficult app that connects to a server to get information for
our database here.
this server is our access point to some equipment in the field that we
monitor.

the messages come in over a socket connection. And according to their
(very limited) documentation, are set up in a particular order. like
this

STX [length indicator] [message type] [message body] ENX

length indicator = length of the message body in 4 bytes
message type = the code for what type of message is being sent
   for example 200 = login
message body = the actual command to send to the server

STX and ENX are the values assigned to start and stop a message.
they are literally 'STX' and 'ENX'


when i capture a message i can print it to the screen and the 'STX' at
the beginning and the 'ENX' at the end are discernable, but the rest of
the message looks like this..

\x00\x00\x00,\x00\x00\x00\e17758\x00\x00   and so on and so forth...
with some commas and other symbols in there. (the e before the 17758
has a little hat on it)
 If i print it out to a text file, i get this...
STXNULNULNULea17758NULLNULL etc..

now the 17758 is significant because it is the actual unit number of
the machine we want to monitor. I just dont know how to extract the
real values out of this message.

anyone have an idea where to start? i have experimented with struct,
but do not know enough about it. Does anyone know a good tutorial about
learning byte codes and such. The docs on pythons website explain the
module well, but i still do not know what to do with it. Or how to
generate a message or pull apart these values to get a message out of
what the server sends us. 

thanks
sk




More information about the Python-list mailing list