Giter Club home page Giter Club logo

chatserver's Introduction

Simple chat server

1. 请求处理流程

client
+----------------------------------------------------------------+
|      +-------+       +--------------+       +--------------+   |
|      |content| ----> |request method| ----> |create packet |   |
|      +-------+       +--------------+       +--------------+   |
|                                                    |           |
|      +--------------+       +----+          +--------------+   |
|      |TCP RECEIVE   | ----> |data|          |TCP SEND      |   |
|      +--------------+       +----+          +--------------+   |
|             |                                      |           |
+----------------------------------------------------------------+
|             |                                      |           |
|      +--------------+                       +--------------+   |
|      |TCP SEND      |                       |TCP RECEIVE   |   |
|      +--------------+                       +--------------+   |
|             |                                      |           |
|      +--------------+       +-------+       +--------------+   |
|      |handle request| <---- |router | <---- |parse packet  |   |
|      +--------------+       +-------+       +--------------+   |
|                                                                |
+----------------------------------------------------------------+
                                                            server

2. 报文格式

  • 注册报文
+------------+----+-------+----+
|request type|name|ip addr|port|
+------------+----+-------+----+
  • 转发报文
+------------+--------+--------+-------+
|request type|src name|dst name|content|
+------------+--------+--------+-------+
  • 操作报文
+------------+--------+--------+
|request type|src name|dst name|
+------------+--------+--------+

3. 客户端指令

  • REGISTER 注册用户
  • REFLECT 消息回射
  • TRANSFER 消息转发
  • BROADCAST 消息广播
  • GETALLUSER 获取所有用户名
  • LOGOUT 登出
  • ADMIN 升级为管理员
  • KICKOUT 剔除用户
  • BANTALK 禁言
  • SHUTDOWN 关闭服务器

4. 总结

不想再造轮子了=_=
1. 多个线程读取一个不存在写操作的共享资源不必加锁,存在写操作必须加锁
2. 聊天服务器可以扩展为多进程或者多机器之间的交互程序 

chatserver's People

Contributors

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