# zie ProgrammeursleerlingExtra.py
# Aanvulling 49
# onderdeel Server extern met client 2

import socket

print( 'server1.py for CPython' )

host = ''
port = 5000
srvaddr = host, port

def server():
    with socket.socket() as srv:
        srv.bind( srvaddr )
        srv.listen()
        print( 'server listen', srvaddr )
        clnt, claddr = srv.accept()
        with clnt:
            print( 'server connect', claddr )
            while True:
                data = clnt.recv( 1024 )
                # print( 'data', data )

                # if data == b'': 
                if data == b'stop':
                    print( 'server client done' )
                    break
                data = b'echo:' + data
                clnt.sendall( data )
                print( 'server', data )
    print( 'end server' )

server()
