#!/usr/bin/python3 # -*- coding: utf-8 -*- import socket # Create a socket object (defaults to AF_INET and SOCK_STREAM) s = socket.socket() # Get local name, 127.0.0.1 and localhost work host = socket.gethostname() print(host) # Reserve a port for your service. port = 12345 # Bind to the port, host could be '' s.bind((host, port)) # Now wait for client connection. s.listen(5) while True: # Establish connection with client. c, addr = s.accept() print("Got connection from", addr) c.send("Thank you for connecting".encode()) c.close()