common approach in socket programming

Uwe Mayer merkosh at
Fri Jun 7 05:18:34 EDT 2002


i want to use the module SocketServer to create a tcp server. with it i 
want to work on arbitrary packet lengths. f.e. from the contents of each 
packet an md5 hash is created and send back. so it makes a difference 
weather i hash each single packet or collect packages and then create 
the hash.
SocketServer offers two possibilities to deal with incomming 
connections. either use self.request which is a socket object, or use 
the file wrapper.
now my problem is how to know that 

a) a connection is still open

i couldn't find a opened() or isopen() function or a similar attribute 
in the documentation. not for the socket object. for the file object 
there should be the open attribute.

b) how do i know the size of each packet?

using the file wrapper the method calls block until the buffer has been 
filled. i could set the maximum buffer size to 1 byte, but thats somehow 
odd to read data bytewise - and: how do i know i haven't crossed packet 
boundaries to a newly arrived packet while i was busy receiving single 
bytes from the tcp/ip layer?

what is the usual solution to something like that?
i don't really want to use own header information to determine packet 
lengths nor would udp packeges suffice because transmission isn't 

Any ideas?
Thanks in advance

More information about the Python-list mailing list