A Multithreaded Uppercase Server : TCP « Network « Python






A Multithreaded Uppercase Server

 
import SocketServer
import netstring
import sys
import string

class MyRequestHandler(SocketServer.BaseRequestHandler):
    def handle(self):
        print "Connected:", self.client_address
        while 1:
            rq = netstring.readns(self.request)
            print "From:", self.client_address, rq
            sys.stdout.flush()
            if rq == "":
                break
            netstring.writens(self.request, string.upper(rq))

myServer = SocketServer.ThreadingTCPServer(('', 8081),
                MyRequestHandler)
myServer.serve_forever()

   
  








Related examples in the same category

1.An Uppercase Client Using TCP
2.A Simple TCP Socket Client: Echo client program
3.A Simple TCP Socket Server: Echo server program
4.A Persistent Uppercase Server Using TCP