parsing packets

Littlefield, Tyler tyler at tysdomain.com
Sun Jul 10 16:59:29 EDT 2011


Hello all:
I'm working on a server that will need to parse packets sent from a 
client, and construct it's own packets.
The setup is something like this: the first two bytes is the type of the 
packet.
So, lets say we have a packet set to connect. There are two types of 
connect packet: a auth packet and a connect packet.
The connect packet then has two bytes with the type, another byte that 
notes that it is a connect packet, and 4 bytes that contains the version 
of the client.
The auth packet has the two bytes that tells what packet it is, one byte 
denoting that it is an auth packet, then the username, a NULL character, 
and a password and a NULL character.

With all of this said, I'm kind of curious how I would 1) parse out 
something like this (I am using twisted, so it'll just be passed to my 
Receive function), and how I get the length of the packet with multiple 
NULL values. I'm also looking to build a packet and send it back out, is 
there something that will allow me to designate two bytes, set 
individual bits, then put it altogether in a packet to be sent out?

-- 

Take care,
Ty
my website:
http://tds-solutions.net
my blog:
http://tds-solutions.net/blog
skype: st8amnd127
My programs don't have bugs; they're randomly added features!




More information about the Python-list mailing list