import socket


# Server that receives a message and returns it upper
#
# Any server socket does nothing but to generate client sockets


# server runs on port 5000
port = 5000

# create socket
s = socket.socket()

# bind socket to port 5000
s.bind((socket.gethostname(), port))

# socket will listen to only one connection (max is 5)
s.listen(1)
print("Connected to client")




while True:
    # accept any connection
    (clientSocket, address) = s.accept()

    # do anything with the client socket
    message = clientSocket.recv(1024)
    # message is in byte type, we need to decode it
    print('Received: ' + str(message.decode('ascii')))

    # send back upper message
    clientSocket.send(str(message.decode('ascii')).upper().encode())

# terminate the socket
s.close()


