Skip to content

Instantly share code, notes, and snippets.

@studiawan
Last active March 11, 2021 06:21
Show Gist options
  • Save studiawan/6710557 to your computer and use it in GitHub Desktop.
Save studiawan/6710557 to your computer and use it in GitHub Desktop.
Simple server receives one message from client and it's done.
import socket
# define server address, create socket, bind, and listen
server_address = ('localhost', 5000)
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(server_address)
server_socket.listen(1)
# accept client, receive its message and print
client_socket, client_address = server_socket.accept()
data = client_socket.recv(1024)
print(data)
# close socket client and socket client
client_socket.close()
server_socket.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment