Skip to content

Instantly share code, notes, and snippets.

@BMU-Verlag
Created January 23, 2020 13:53
Show Gist options
  • Save BMU-Verlag/6141a9ea25d5f06525fb56b24657a10f to your computer and use it in GitHub Desktop.
Save BMU-Verlag/6141a9ea25d5f06525fb56b24657a10f to your computer and use it in GitHub Desktop.
def receive():
try:
message_size = client_socket.recv(LENGTH_HEADER_SIZE)
if message_size:
message_size = int(message_size.decode('utf-8').strip())
sender = client_socket.recv(USER_HEADER_SIZE).decode('utf-8').strip()
message = client_socket.recv(message_size).decode('utf-8')
print_message (f'\n{sender} > {message}')
except IOError as e:
if e.errno != errno.EAGAIN and e.errno != errno.EWOULDBLOCK:
print('Encountered error while reading', e)
client_socket.close()
sys.exit()
except Exception as e:
client_socket.close()
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment