Create a socketserver at least in the following steps:
- First, you must create a request handler class by subclassing the Baserequesthandlerclass and overriding its handle () meth Od This method would process incoming requests.
- Second, you must instantiate one of the server classes, passing it the server ' s address and the request handler class.
- Then call the Handle_request () Orserve_forever () method of the server object to process one or many requests.
- Finally, call Server_close () to close the socket.
1, create a request processing class yourself, 2, instantiate a TCP server yourself, and pass the server IP and the request processing class you created above 3, import socketserver Class Mytcphandler (Socketserver. Baserequesthandler): "" "The request handler class for we server. it is instantiated once per connection to the server , and MustOverride the handle () method to implement communication to theclient. "" " def handle (self): # Self.request was the TCP socket connected to the clientwhile True:try:self.data = Self.request.rec V (1024x768). Strip () print ("{} wrote:". Format (Self.client_address[0])) print (Self.data) self.request.send ( Self.data.upper ()) except Connectionabortederror as E:print ("Err", e) break if __name__ = = "__main__": HOST, PORT = " LocalHost ", 1111 # Create the server, binding to localhost on port 9999server = Socketserver. Threadingtcpserver (HOST, PORT), Mytcphandler) Server.serve_forever () Threadingtcpserver supports multithreaded 4, individual dictionaries per user 5, running 7 on Linux, MOD5 authentication 8, percent 9, Breakpoint Continuation: The file size (bytes) in the temporary file is paused, continuedWhen reading temporary files
Python Growth Notes-Basics (ix)