# Start a server, on ‹localhost›, on the given port (using # ‹asyncio.start_server›) and have two clients connect to it. The # server takes care of the underlying sockets, so we will not be # creating them manually. Data is, again, transferred as ‹bytes› # object. # The server should return whatever data was sent to it. Clients # should send ‹hello› and ‹world›, respectively, then wait for the # answer from the server and return this answer. Add ‹print› # statements to make sure your server and clients behave as # expected; print data received by the server, sent to the clients # and sent and received by the clients on the client side. Make sure # to close the writing side of sockets once data is exhausted. import asyncio # Server-side handler for connecting clients. Read the message from # the client and echo it back to the client. async def handle_client( reader, writer ): pass # print( "server received & sending", ... ) # Client: connect to the server, send a message, wait for the answer # and return this answer. Assert that the answer matches the message # sent. Sleep for 1 second after sending ‹world›, to ensure message # order. async def client( port, msg ): pass # print( "client sending", ... ) pass # print( "client received", ... ) # Start the server and the two clients, gather the data back from # the two clients into a list, return this list; starting with the # ‹hello› client. Use the provided port. async def start( port ): pass def test_main() -> None: import sys import random from io import StringIO stdout = sys.stdout out = StringIO() sys.stdout = out data = asyncio.run( start( random.randint( 9000, 13000 ) ) ) assert data == ( 'hello', 'world' ), data sys.stdout = stdout output_ = out.getvalue() output = output_.split('\n') assert 'client sending hello' in output[ 0 : 3 ], output assert 'client sending world' in output[ 0 : 3 ], output assert 'server received & sending hello' in \ output[ 1 : 3 ], output assert 'server received & sending world' in \ output[ 2 : ], output if __name__ == "__main__": test_main()