''' client.py A program to facilitate a guessing game between a client and server using sockets Nate Weeks, April 2018 ''' # Import socket module import socket # Create a socket object s = socket.socket() # Define the port on which you want to connect port = 12345 # connect to the server on local computer s.connect(('127.0.0.1', port)) # print received data print s.recv(1024) # set a response and guess response = "" guess = "" # loop through guesses until server responds with specified success message while response != "You guessed correct! the number was {}, closing connection".format(guess): guess = raw_input("type your guess: ") # send guess to server s.send(guess) # receive data from the server response = s.recv(1024) print response # close the connection s.close()