SocketServer and Timeout

John Abel john.abel at pa.press.net
Tue May 27 08:33:32 EDT 2003


That would depend on your version of Python. 2.3 has support for timeout 
on sockets.  For 2.2, you will need the timesocket module (a google 
search should turn this up).

HTH

John

Toorop wrote:

>Hi,
>   
>  I'm studing the SocketServer class and I didn't find the way to put a timeout
>  if a client doesn't send request during X sec.
>  Here is my code :
>  (PoproxSession is a pop class, the aim of the complete script is to implemente a
>  pop3 proxy in Python)
>
>-------------------------------------------------------------------------------
>
>import SocketServer, string, time
>                        
>class CoreServer(SocketServer.ThreadingTCPServer) :
>      def __init__(self, server_address, RequestHandlerClass):
>          SocketServer.ThreadingTCPServer.__init__(self, server_address,RequestHandlerClass)
>
>class PoproxHandler(SocketServer.StreamRequestHandler):
>      def handle(self):
>          from bin import poprox
>          # Instanciation d'une session Pop
>          poprox=poprox.PoproxSession()
>          print self.client_address,time.ctime()
>          print self.request
>          poprox.runsession=1
>          self.request.send(poprox.sendHello())
>          while poprox.runsession :
>              data_in=string.strip(self.request.recv(1024))
>              data_out,poprox.runsession=poprox.answer(data_in)
>              try : self.request.send(data_out)
>              except : runsession=0
>          self.request.close()
>
>        
>
>if __name__ == "__main__" :
>      from data import config
>      poproxServer=CoreServer((config.serverIp,config.serverPort),PoproxHandler)
>      poproxServer.serve_forever()
>
>-------------------------------------------------------------------------------
>
>
>Thank for your help
>
>Escuse my poor english ;-)
>
>--                                                                            
>Toorop
>
>
>  
>







More information about the Python-list mailing list