Skip to content

Instantly share code, notes, and snippets.

@ahmedfgad
Created June 22, 2020 11:02
Show Gist options
  • Select an option

  • Save ahmedfgad/0db41e35803436c7eb61860146d7508e to your computer and use it in GitHub Desktop.

Select an option

Save ahmedfgad/0db41e35803436c7eb61860146d7508e to your computer and use it in GitHub Desktop.
import socket
import pickle
soc = socket.socket()
print("Socket is created.")
soc.connect(("localhost", 10000))
print("Connected to the server.")
msg = "A message from the client."
msg = pickle.dumps(msg)
soc.sendall(msg)
print("Client sent a message to the server.")
received_data = b''
while str(received_data)[-2] != '.':
data = soc.recv(8)
received_data += data
received_data = pickle.loads(received_data)
print("Received data from the client: {received_data}".format(received_data=received_data))
soc.close()
print("Socket is closed.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment