SocketServer Timestamp TCP Server (tsTservSS.py) : ServerSocket « Network « Python Tutorial






from SocketServer import (TCPServer as TCP,
     StreamRequestHandler as SRH)
from time import ctime

HOST = '127.0.0.1'
PORT = 21567
ADDR = (HOST, PORT)

class MyRequestHandler(SRH):
     def handle(self):
          print '...connected from:', self.client_address
          self.wfile.write('[%s] %s' % (ctime(),
              self.rfile.readline()))

tcpServ = TCP(ADDR, MyRequestHandler)
print 'waiting for connection...'
tcpServ.serve_forever()








21.4.ServerSocket
21.4.1.Receiving Streaming Data Using the ServerSocket Module
21.4.2.SocketServer Timestamp TCP Server (tsTservSS.py)
21.4.3.SocketServer Timestamp TCP Client