Categories
Linux Networking Programming

Trio Tutorial – Simple TCP Chat Program – Part 3

Series

Part 1: https://jaytuckey.name/2021/07/22/trio-tutorial-simple-tcp-chat-program-part-1/

Part 2: https://jaytuckey.name/2021/07/24/trio-tutorial-simple-tcp-chat-program-part-2/

In part 3 we build more of the server. We build out the functionality to receive messages, then distribute them to all connected users.

For this part we use Trio’s nurseries to start up new running tasks: https://trio.readthedocs.io/en/stable/reference-core.html#nurseries-and-spawning

We use the nursery.start_soon() function to kick off new tasks in the background.

The other tool we use another tool from Trio, the memory channels: https://trio.readthedocs.io/en/stable/reference-core.html#using-channels-to-pass-values-between-tasks

For this we use the trio.open_memory_channel() function to create a channel and get a send+receive channel, which we then use to distribute the messages between connected users.

Got any questions? Contact me: https://jaytuckey.name/about/

Leave a Reply

Your email address will not be published. Required fields are marked *