tcpclient.py (442B)
1 import socket 2 3 HOST = "127.0.0.1" 4 PORT = 8558 5 6 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # cf. tcpserver.py 7 print('Socket created') 8 9 s.connect((HOST,PORT)) 10 print('Connected to', HOST, ':', PORT) 11 12 data = "" # Initialize data 13 14 while(data != 'q'): 15 msg = input("Say: ") 16 s.sendall(msg.encode()) 17 data = s.recv(1024).decode() 18 print('Echo:', repr(data)) 19 20 s.close() 21 print('Connection closed')