Categories
Linux Networking Programming

Trio Tutorial – Simple TCP Chat Program – Part 1

I’ve made a video about making a simple TCP-based program using Python and Trio. The video is here: https://www.youtube.com/watch?v=6JM1hgjLV-A

The features I plan to build are:

  • each user has a long running tcp connection
  • user is asked for name on connection
  • user sends message
  • each other connected user receives the message

In part 1 we get the basic connectivity working, and build the ability for a user to send through a username on connection.

To listen for connections we use the trio.serve_tcp function: https://trio.readthedocs.io/en/stable/reference-io.html#trio.serve_tcp

When a user connects it calls our async function, and provides it a trio.SocketStream : https://trio.readthedocs.io/en/stable/reference-io.html#trio.SocketStream

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

Leave a Reply

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