Git Product home page Git Product logo

multiclientwebchat's Introduction

MultiClientWebChat

基于 Spring Websocket 和心跳保活重连的多人网页聊天室

Only for practice

Feature and Achieve

Schedule

  • Multiple client chat
  • Client reconnecting mechanism
  • Client keep alive and reconnect using heartbeat
  • MessageQueue broke

Multiple client chat

  • 当一个客户端打开,即建立一个与服务器的websocket连接,同时服务端将此 sessionId 加入到消息队列中
  • 当一个客户端发送信息时,服务器接收信息并将其广播给连接的所有客户端
  • 当一个客户端断开时,服务器将其从消息队列中移除

Client reconnecting mechanism

  • 若 client-server 通信发生中断,触发客户端onclose event,主动重连

Client keep alive and reconnect using heartbeat

存在这样的情况:

  • 超过一定的时间客户端和服务器之间没有发生任何消息传输,导致websocket连接自动断开。

  • websocket通信出错,但无法触发客户端 close 事件,导致客户端无法获知中断状况,编写在onclose中的重连逻辑也因此失效。

解决方法:设计客户端心跳保活+重连机制

客户端设置计时器,每次收到任何信息都将计时器归零,当计时器到时,发送一个心跳包(作用①保活,②检测连接状态),若服务器返回响应,则将计时器归零后重新启动;若服务器响应时间超时(认定为没有响应),则说明连接中断,执行重连逻辑。

MessageQueue broke

  • 使用专用消息队列作为消息中间层

multiclientwebchat's People

Contributors

firejq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.