import socket host = '192.168.50.106' port = 2000 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((host, port)) while True: data = input('Enter data to send: ') s.send(data.encode('utf-8')) if data == 'exit': break data = s.recv(1024) print('Received data: ', data.decode('utf-8'))