network programming and sockets handlers to use the moduleyou define handler class that inherits from the base class baserequesthandler an instance of baserequesthandler implements one or more of the following methodsh finish(called to perform cleanup actions after the handle(method has completed by defaultit does nothing it' not called if either the setup(or handle(method generates an exception handle(this method is called to perform the actual work of request it' called with no argumentsbut several instance variables contain useful values request contains the requesth client_address contains the client addressand server contains an instance of the server that called the handler for stream services such as tcpthe request attribute is socket object for datagram servicesit' byte string containing the received data setup(this method is called before the handle(method to perform initialization actions by defaultit does nothing if you wanted server to implement further connection setup such as establishing ssl connectionyou could implement it here here is an example of handler class that implements simple time server that operates with streams or datagramstryfrom socketserver import baserequesthandler except importerrorfrom socketserver import baserequesthandler import socket import time python python class timeserver(baserequesthandler)def handle(self)resp time ctime("\ \nif isinstance(self request,socket socket) stream-oriented connection self request sendall(resp encode('latin- ')elsea datagram-oriented connection self server socket sendto(resp encode('latin- '),self client_addressif you know that handler is only going to operate on stream-oriented connections such as tcphave it inherit from streamrequesthandler instead of baserequesthandler this class sets two attributesh wfile is file-like object that writes data to the clientand rfile is file-like object that reads data from the client here is an exampletryfrom socketserver import streamrequesthandler except importerrorfrom socketserver import streamrequesthandler import time python python lib fl ff