Skip to content
/ webchat Public

realtime webchat app using aiohttp and redis-py

Notifications You must be signed in to change notification settings

pderer/webchat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Multi-user Single-room Realtime Webchat

Realtime chat was implemented using WebSocket and asynchronous programming(asyncio). If you push connect button, you get random name to chat another user. Connected, disconnected, and chatting messages are displayed. Enjoy Realtime chatting!

스크린샷 2023-07-03 11 16 27

Table of Contents


How It Works

Webchat is implemented by WebSocket protocol. If the server runs in one python process, we can share the state using the aiohttp.webApplication object. However, if we extend server, we need another data structure to share the state of all servers. Redis is used to share the state when the server expands. And to implement real time request/response, we used asynchronous programming through asyncio.

aiohttp

To implement asynchronous request, response and websocket protocol, I used aiohttp framework.

redis-py

To share the state of all servers, I used redis-py. In particular, redis pub/sub mode, which is specialized in message delivery, was used.

asyncio

If redis message publishing/subscribing process (I/O) is implemented synchronously, performance is low. Realtime chatting was implemented by setting redis pub/sub as a task and using asyncio.createtask to improve the performance of the I/O process asynchronously using eventloop.

Installation

Built a self-contained Docker image that runs webchat app.

docker-compose

Used docker-compose to run python and redis together.

  1. clone this project.
$ git clone https://github.com/pderer/webchat.git
  1. docker compose.
$ docker-compose up --build
  1. connect URL and enjoy realtime chat.
    http://localhost:8080

About

realtime webchat app using aiohttp and redis-py

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors