├── client.py └── server.py /client.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 4 | s.connect((socket.gethostname(), 1234)) 5 | 6 | full_msg = '' 7 | 8 | while True: 9 | msg = s.recv(1024) # Defining the size of the data chunks, buffer size 10 | if len(msg) <= 0: 11 | break 12 | full_msg += msg.decode('utf-8') 13 | 14 | print(msg.decode('utf-8')) 15 | -------------------------------------------------------------------------------- /server.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 4 | s.bind((socket.gethostname(), 1234)) # Define end point for communication 5 | s.listen() 6 | print('Localhost server is running.') 7 | 8 | while True: 9 | clientsocket, address = s.accept() 10 | print(f'Connection from {address} has been established.') 11 | clientsocket.send(bytes('Welcome to the server', 'utf-8')) 12 | --------------------------------------------------------------------------------