import socket s = socket.socket() # instantiate host = socket.gethostname() # as both code is running on same pc port = 12345 # socket server port number s.connect((host, port)) # connect to the server message = input(" -> ") # take input while message.strip() != 'STOP': s.send(message.encode()) # send message data = s.recv(1024).decode() # receive response print('Received from server: ' + data) # show in terminal message = input(" -> ") # again take input s.close() # close the connection