This is a simple implementation for TCP server and client. The server listens for the port 9090 of the localhost, receives messages from any connected clients, and sends them to all connected peers. The client is started with a username as an argument, reads in an infinite loop messages from the string, re-format them as "name > message\n" and send to the server. In a different async function it also waits for message from the server and prints the to the console.
Files:
aio_chat_client.py
: client implementationaio_chat_server.py
: server implementation
Dependencies: Python 3.6+ and aioconsole
Install aioconsole
pip install aioconsole
Start server as this:
python ./aio_chat_server.py
Start two clients in separate consoles as
python ./aio_chat_server.py Foo
and
python ./aio_chat_server.py Bar
Try to write a message in any console.
More info:
- asyncio echo client and server
- aioconsole. The documentation is unfortunately not very complete, but it seems to work, and should also work under Windows
- simplified introduction into asyncio