This commit is contained in:
2015-06-02 21:38:24 +02:00
parent 219ffcce0f
commit 1151d6893e
5 changed files with 141 additions and 0 deletions

21
socketserver/TcpClient.py Normal file
View File

@@ -0,0 +1,21 @@
import socket
import sys
HOST, PORT = "localhost", 9999
data = " ".join(sys.argv[1:])
# Create a socket (SOCK_STREAM means a TCP socket)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
# Connect to server and send data
sock.connect((HOST, PORT))
sock.sendall(bytes(data + "\n"))
# Receive data from the server and shut down
received = str(sock.recv(1024));
finally:
sock.close()
print("Sent: {}".format(data))
print("Received: {}".format(received))