rendered paste bodyimport asyncore, asynchat
import os, socket, string
PORT = 8100
class SOCKETChannel(asynchat.async_chat):
data = ""
def __init__(self, server, sock, addr):
asynchat.async_chat.__init__(self, sock)
self.set_terminator("\n")
def collect_incoming_data(self, data):
SOCKETChannel.data = SOCKETChannel.data + data
def found_terminator(self):
self.push(SOCKETChannel.data)
class SOCKETServer(asyncore.dispatcher):
def __init__(self, port):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.bind(("", port))
self.listen(5)
def handle_accept(self):
conn, addr = self.accept()
SOCKETChannel(self, conn, addr)
#
# try it out
s = SOCKETServer(PORT)
print "serving at port", PORT, "..."
asyncore.loop()