Skip to content

Instantly share code, notes, and snippets.

@leVirve
Created April 10, 2015 15:22
Show Gist options
  • Save leVirve/b3eafb09fb932a274d4f to your computer and use it in GitHub Desktop.
Save leVirve/b3eafb09fb932a274d4f to your computer and use it in GitHub Desktop.
socket-client in Python3
import socket
import sys
HOST, PORT = "localhost", 5566
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect((HOST, PORT))
for data in sys.stdin:
sock.sendall(bytes(data + "\n", "utf-8"))
received = str(sock.recv(1024), "utf-8")
finally:
sock.close()
print("Sent: {}".format(data))
print("Received: {}".format(received))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment