import socket # This block starts a server listen for a connection our_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) our_socket.bind(("0.0.0.0", 5103)) our_socket.listen() # This is how you exchange data with a client while True: conn_socket, addr = our_socket.accept() print("New connection from: ", addr) # instead of send/receive, start a new thread for the client! # We didn't do that yet, so the following code doesn't make new threads # If you want to, Python has a function called start_new_thread try: conn_socket.send(b"Good morning!"); print(conn_socket.recv(100)) conn_socket.close() except Exception as e: print("we had some kind of failure:", e) our_socket.close()