Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1.         with self.create_socket() as sock:
  2.             logger.info(f"Listen on: {self.addr}")
  3.             while True:
  4.                 conn, addr = sock.accept()
  5.                 logging.info(f"New connection: {addr}")
  6.                 data = bytearray()  # Все данные от клиента
  7.                 while True:
  8.                     r_data = conn.recv(1024)
  9.                     data.extend(r_data)
  10.                     if len(r_data) < 1024:
  11.                         break
  12.                 # Обрабатываем http запрос
  13.                 req = Request.from_http_bytes(addr, data)
  14.                 response = self.router.process_request(req)
  15.                 if response:
  16.                     conn.sendall(response)
  17.                 # Закрываем соединение
  18.                 logger.info(f"Close connection: {addr}")
  19.                 conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement