A Persistent Uppercase Server Using TCP : TCP « Network « Python






A Persistent Uppercase Server Using TCP

 

import SocketServer
import netstring

class MyRequestHandler(SocketServer.BaseRequestHandler):
    def handle(self):
       print "From:", self.client_address
       while 1:
           rq = netstring.readns(self.request)
           print rq
           netstring.writens(self.request, rq.upper())
           if rq.lower() == "end":
               break

myServer = SocketServer.TCPServer(('', 8081),
                MyRequestHandler)
myServer.handle_request()

   
  








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 Multithreaded Uppercase Server