Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import typing
  2.  
  3.  
  4. class Server:
  5.    
  6.     def main(self, port):
  7.         # init socket at given port and listen it
  8.         socket = object()
  9.         socket.listen(port, self.handle_request)
  10.         pass
  11.    
  12.    
  13.     def handle_request(self, bytes_received):
  14.         str_received = RequestHandler.handle_request(bytes_received)
  15.        
  16.         need_sync = 'need_sync' in str_received
  17.        
  18.         if need_sync:
  19.             # asynchronous
  20.             self.perform_sync()
  21.        
  22.  
  23.     def perform_sync(self, *args):
  24.         pass
  25.  
  26.  
  27. class RequestHandler:
  28.    
  29.     @staticmethod
  30.     def send_request(ip, port, request_to_send):
  31.         bytes_to_send = Serializer.from_str_to_bytes(request_to_send)
  32.         # send_request_to(ip + ':' + port, bytes_to_send)
  33.         pass
  34.  
  35.     @staticmethod
  36.     def handle_request(bytes_from_client):
  37.         str_received = Serializer.from_bytes_to_str(bytes_from_client)
  38.         return str_received
  39.  
  40.  
  41.  
  42. class Serializer:
  43.     @staticmethod
  44.     def from_bytes_to_str(bytes) -> str:
  45.         pass
  46.    
  47.     @staticmethod
  48.     def from_str_to_bytes(str) -> typing.List[bytes]:
  49.         pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement