Skip to content

rusheb/chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chat

A very basic async chat app that I built to help me learn asynchronous programming with asyncio.

Clients can connect to the server, see who's online, and chat in real-time. The server handles client disconnects and errors gracefully.

This project was inspired by the really awesome import asyncio youtube series.

Demo

chatroom_demo.mp4

Usage

Install dependencies

  • Get Poetry
  • Install dependencies with poetry install

Run Server

poetry run python chat_server.py

Run Client

Start multiple clients, each in a separate terminal:

poetry run python chat_client.py <client_name>

Implementation Notes / Lessons Learned

  • Simulated latency: I introduced artificial delays using asyncio.sleep() to mimic network latency and understand its implications on the chat flow.
  • User-specific queues: I implemented individual message queues for each user. This ensures message order and keeps messages isolated, whilst still allowing concurrency across different users.
  • Task management: I used a set to track active asyncio tasks. This makes it easy to clean up and avoid dangling tasks.
  • Testing: I used pytest-asyncio to test the project's async functions.

About

A basic async terminal chatroom app that I built to help me learn asynchronous programming with asyncio.

Topics

Resources

Stars

Watchers

Forks