def recv_bytes(self, connection):
"""
Given a socket connection, receive up to 2048 bytes
from its buffer and return that data as a bytes object.
Returns an empty bytes object if there is no data to receive.
"""
try:
bytes_message = connection.recv(2048)
except BlockingIOError:
# Non-blocking socket couldn't immediately receive.
return None
except ConnectionResetError:
self._print_message('Connection was reset.')
self.connection.close()
_thread.interrupt_main()
return bytes_message
评论列表
文章目录