dumb_tcp_client.py
1 """ 2 This is just a script for testing that the dumb TCP server actually works 3 correctly, for verifying that problems with tests are in Vim. Pass the 4 same port number given to the test server to check that it's working. 5 """ 6 import socket 7 import sys 8 9 10 def main(): 11 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 12 result = sock.connect_ex(('127.0.0.1', int(sys.argv[1]))) 13 14 if result: 15 sock.close() 16 sys.exit("Couldn't connect to the socket!") 17 18 data_sent = 'x' * 1024 19 20 sock.send(data_sent) 21 data_received = sock.recv(1024) 22 23 if data_sent != data_received: 24 sock.close() 25 sys.exit("Data sent didn't match data received.") 26 27 sock.close() 28 29 print("Everything was just fine.") 30 31 32 if __name__ == "__main__": 33 main()