A Simple Server to Capture Single Short Requests : Socket Server « Network « Python






A Simple Server to Capture Single Short Requests

 

import SocketServer

class MyRequestHandler(SocketServer.BaseRequestHandler):
    def handle(self):
       print "From:", self.client_address
       input = self.request.recv(10240)
       print input.replace('\r', '')
       self.request.send("HTTP/1.1 200 OK\r\n")
       self.request.send("Content-Type: text/html\n\n")
       self.request.send("<HTML><BODY><H2>Hello!</H2></BODY></HTML>")
       self.request.close()

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

   
  








Related examples in the same category

1.Server Bound to Specific Address
2.Delaying Server
3.Simple Server waiting for connections
4.Simple Server
5.Echo Server