Winand

Untitled

Feb 11th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1.     import SocketServer
  2.     class BackgroundReqHandler(SocketServer.BaseRequestHandler, SocketPipe):
  3.         def route(self, path, *args):
  4.             handler = HDLRS.get(path, None)
  5.             if handler: handler(self, *args)
  6.             else: error("server handler", path, "not found")
  7.    
  8.         def handle(self):
  9.             self.route(*self.recv_data())
  10.    
  11.     #Reuse a local socket in TIME_WAIT state, without waiting for its timeout to expire
  12.     class BackgroundServer(SocketServer.ThreadingTCPServer):
  13.         allow_reuse_address = True
  14.     server = BackgroundServer((SHARED_SERVER_ADDR, SHARED_SERVER_PORT), \
  15.                                                         BackgroundReqHandler)
  16.     debug("start listening...")
  17.     server.serve_forever()
Advertisement
Add Comment
Please, Sign In to add comment