#server.py
import socket # Import socket module s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Create a socket object host = socket.gethostname() # Get local machine name port = 12345 # Reserve a port for your service. s.bind((host, port)) # Bind to the port s.listen(5) # Now wait for client connection. while True: print("waiting for client connection" ) c, addr = s.accept() # Establish connection with client. print ('Got connection from', addr) c.send('Thank you for connecting')) c.close() # Close the connection#client.py
import socket # Import socket module s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Create a socket object host = socket.gethostname() # Get local machine name port = 12345 # Reserve a port for your service. s.connect((host, port)) print(s.recv(1024)) s.close # Close the socket when done