# server.py

import socket

HOST = 'localhost' # For same computer as client
PORT = 20000 # Low numbers are reserved for SSH, HTTP, SQL, et al.

sock = socket.socket()

try:
    sock.bind((HOST, PORT)) # Note tuple!

except Exception as e:

    print('bind() failed ' + str(e))
    exit(0)

sock.listen(1) # handle up to 1 back-logged connection

print('Waiting for a client ...')

client, address = sock.accept()

print('Accepted connection')

while True:

    msg = input('Say something to the client > ')

    if len(msg) < 1:
        break

    try:
        client.send(msg.encode()) # encoding is required since Python3.0

    except Exception as e:
        print('Failed to transmit: ' + str(e))
        break

client.close()
sock.close
