34 lines
825 B
Python
34 lines
825 B
Python
import socket
|
|
# Get local machine name
|
|
HOST = socket.gethostname("localhost")
|
|
PORT = 5050
|
|
|
|
def handleClient(clientsocket):
|
|
while True:
|
|
# Receive no more than 1024 bytes
|
|
msg = clientsocket.recv(1024)
|
|
if not msg:
|
|
break
|
|
clientsocket.send(msg)
|
|
clientsocket.close()
|
|
|
|
def start():
|
|
# Create a socket object
|
|
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
|
|
# Bind to the port
|
|
serversocket.bind((HOST, PORT))
|
|
|
|
# Queue up to 5 requests
|
|
serversocket.listen(5)
|
|
|
|
while True:
|
|
# Establish a connection
|
|
clientsocket, addr = serversocket.accept()
|
|
|
|
print("Got a connection from %s" % str(addr))
|
|
|
|
msg = 'Thank you for connecting' + "\r\n"
|
|
clientsocket.send(msg.encode('ascii'))
|
|
clientsocket.close() |