multi command session through a socket

Nomad nomad*** at ***freemail.absa.co.za
Fri Oct 12 16:11:48 CEST 2001


On 12 Oct 2001 12:28:02 GMT, Gordon McMillan <gmcm at hypernet.com>
wrote:

>Nomad wrote:
>
>> I've been playing with sockets and serversockets in Python (2.1 win32)
>> for the last few days.  I've been trying to adapt the code from
>> 'BaseHTTPServer.py' in the standard library, but no matter what I try,
>> the server side always drops the connection after only one command,
>> whereas I'd like to be able to run several commands (like telnetting
>> into a pop3 session) and finishing with a QUIT command (or hopfully
>> later a timeout, but that's another question entirely).
>
>[snip]
>
>>     def handle(self):
>
>[snip]
>
>>      self.quit = 1
>>      while self.quit == 1: # <---- what is wrong here
>>           self.raw_requestline = self.rfile.readline()
>>           if not self.parse_request():
>>                return
>>           
>>     def parse_request(self):  
>
>[snip]
>
>A cursory examination reveals that you
>are always returning a false value
>from parse_request. Looks like "self.quit"
>and the return from parse_request have
>redundant intents and conflicting 
>implementations.
>
>- Gordon

Thanks Gordon, I didn't spot that - looks like I left too much of the
original code in.

I removed the return 0's from parse_request() and changed the handle()
loop to:

#  start test code
	self.quit = 1
	while self.quit == 1:
		self.raw_requestline = self.rfile.readline()
		self.parse_request()
# end test code

and it keeps alive until I give a 'quit' command.  All I have to do
now is work out how to implement a decent timeout function.

Thanks again.

-- 
Nomad

Wondering of the vast emptyness of the 'net
in search of something cool.



More information about the Python-list mailing list