Created
April 10, 2015 15:22
-
-
Save leVirve/b3eafb09fb932a274d4f to your computer and use it in GitHub Desktop.
socket-client in Python3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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