organise files, use same port number in examples

This commit is contained in:
2015-09-06 20:35:09 +01:00
parent 1151d6893e
commit 97613337c6
7 changed files with 10 additions and 21 deletions

21
select/TcpClient.py Normal file
View File

@@ -0,0 +1,21 @@
import socket
import sys
HOST, PORT = "localhost", 10000
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))