GithubHelp home page GithubHelp logo

webchat's Introduction

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

webchat's People

Contributors

pderer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.