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](https://private-user-images.githubusercontent.com/59244452/250427636-1e7e266e-bb12-46f4-8e5a-643fcec2d9a6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM1NTY0MzQsIm5iZiI6MTcyMzU1NjEzNCwicGF0aCI6Ii81OTI0NDQ1Mi8yNTA0Mjc2MzYtMWU3ZTI2NmUtYmIxMi00NmY0LThlNWEtNjQzZmNlYzJkOWE2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODEzVDEzMzUzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWFjNTBhYmIwZGQzYzRiOTgzNmRmMDI4N2Q1ZDA5ZDRhNmMxNTBlYmMyN2E4Zjg5ZTFlMjJhNmI3ZTk3ZTdmNjQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.46bEVTrnQnseipjMB2jyVQmNVHzHgs_Xvlnpm3znm94)
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.
To implement asynchronous request, response and websocket protocol, I used aiohttp framework.
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.
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.
Built a self-contained Docker image that runs webchat app.
Used docker-compose to run python and redis together.
- clone this project.
$ git clone https://github.com/pderer/webchat.git
- docker compose.
$ docker-compose up --build
- connect URL and enjoy realtime chat.
http://localhost:8080