Skip to content

Instantly share code, notes, and snippets.

@RobinDavid
Created February 25, 2014 17:24
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 RobinDavid/9213575 to your computer and use it in GitHub Desktop.
Save RobinDavid/9213575 to your computer and use it in GitHub Desktop.
Another sample of python server
#!/usr/bin/env python
#-*- encoding: utf-8 -*-
import SocketServer
class EchoRequestHandler(SocketServer.BaseRequestHandler):
def setup(self):
print self.client_address, 'connected!'
self.request.send('hi ' + str(self.client_address) + '\n')
def handle(self):
while 1:
data = self.request.recv(1024)
self.request.send(data)
if data.strip() == 'bye':
return
def finish(self):
print self.client_address, 'disconnected!'
self.request.send('bye ' + str(self.client_address) + '\n')
#server host is a tuple ('host', port)
server = SocketServer.ThreadingTCPServer(('localhost', 50000), EchoRequestHandler)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment