Advertisement
Guest User

Untitled

a guest
May 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import SocketServer
  4. import time
  5.  
  6. class GreetingHandler(SocketServer.BaseRequestHandler):
  7.     '''
  8.     Class to handle sending a greeting to a client
  9.    '''
  10.  
  11.     def handle(self):
  12.         '''
  13.         Method to actually handle the greeting
  14.        '''
  15.     print 'Handling the request.'
  16.         data = self.request.recv(1024)
  17.         self.request.sendall('Request received: %s \n' % data)
  18.  
  19. def manageServer():
  20.     '''
  21.     Function to manage the running of the server and handling of requests
  22.    '''
  23.     servObj = SocketServer.TCPServer(('localhost',6099), GreetingHandler)
  24.     print 'Starting the server...'
  25.     servObj.serve_forever()
  26.  
  27. if __name__ == '__main__':
  28.     manageServer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement