import socket
import sys
"""
This program is modified from an example (c)Python Software Foundation
that was posted at https://docs.python.org/3/library/socket.html
"""
HOST, PORT = "", 60000
def handle_client(socket, addr):
try:
socket.setblocking(True)
socket.settimeout(10.0)
data = socket.recv(2048)
socket.sendall(data)
except socket.Timeouterror:
print("Incoming data timeout, exiting")
try:
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind( (HOST, PORT) )
server.listen(1)
except:
server.close()
print("could not open the server socket")
sys.exit(1)
while 1:
try:
client_socket, client_address = server.accept()
handle_client(client_socket, client_address)
except:
print("Problems while handling an incoming client: ", client_socket)
finally:
client_socket.close()