Skip to content

Instantly share code, notes, and snippets.

@ahmedfgad
Created June 23, 2020 19:38
Show Gist options
  • Save ahmedfgad/41dcc9ffeed8727a72aac20825bc74fb to your computer and use it in GitHub Desktop.
Save ahmedfgad/41dcc9ffeed8727a72aac20825bc74fb to your computer and use it in GitHub Desktop.
received_data = b''
if connected:
while True:
recv_start_time = time.time()
time_struct = time.gmtime()
date_time = "Waiting to Receive Data Starting from {day}/{month}/{year} {hour}:{minute}:{second} GMT".format(year=time_struct.tm_year, month=time_struct.tm_mon, day=time_struct.tm_mday, hour=time_struct.tm_hour, minute=time_struct.tm_min, second=time_struct.tm_sec)
print(date_time)
recv_timeout = 5
received_data, status = recv(connection, 8, recv_timeout)
print("Received data from the client: {received_data}".format(received_data=received_data))
if status == 0:
connection.close()
print("Connection Closed either due to inactivity for {recv_timeout} seconds or due to an error.".format(recv_timeout=recv_timeout), end="\n\n")
break
msg = "Reply from the server."
msg = pickle.dumps(msg)
connection.sendall(msg)
print("Server sent a message to the client.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment