Author: subinacls Language: python
Description: tcp threaded socket Timestamp: 2013-06-18 15:52:44 +0000
View raw paste Reply
  1. try:
  2.         class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
  3.                 def handle(self):
  4.                         self.data = self.request.recv(1024).strip()
  5.                         print bcolors.OKBLUE + "Host: %s connected on port: %s\n" % (self.client_address[0],self.data) + bcolors.ENDC
  6.                         self.request.send(self.data)
  7.         class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
  8.                 pass
  9.         socketserver = ThreadedTCPServer(('', lowport), ThreadedTCPRequestHandler)
  10.         socketserver_thread = threading.Thread(target=socketserver.serve_forever)
  11.         socketserver_thread.setDaemon(False)
  12.         socketserver_thread.start()
View raw paste Reply