Skip to content

Instantly share code, notes, and snippets.

@leadscloud
Created December 24, 2014 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leadscloud/2b42d780b8fcbba08c88 to your computer and use it in GitHub Desktop.
Save leadscloud/2b42d780b8fcbba08c88 to your computer and use it in GitHub Desktop.
Python ThreadedTCPServer http://blog.marchtea.com/archives/60
#!/usr/bin/env python
import SocketServer
from threading import Thread
class service(SocketServer.BaseRequestHandler):
def handle(self):
data = 'dummy'
print "Client connected with ", self.client_address
while len(data):
data = self.request.recv(1024)
self.request.send(data)
print "Client exited"
self.request.close()
class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
pass
t = ThreadedTCPServer(('',1520), service)
t.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment