Giter Club home page Giter Club logo

udpchatsystem's Introduction

畅聊系统(UdpChatSystem)

1.项目的基本原理

  • 基于Udp的群聊系统

  • 服务器基于生产者-消费者模型,一个线程收到客户端的数据,该数据放入数据池,另一个线程负责从数据池中拿到数据群发给在线列表中的所有好友

  • 基于环形队列(生产者-消费者模型)实现数据池

  • 借助ncurses库来模拟界面

  • 借助jsoncpp实现数据的序列化与反序列化

2.聊天室功能

  • 客户端可以发送消息给服务器
  • 服务器向所有在线列表中的好友转发数据
  • 客户端退出,其他客户端的在线列表中就没有该好友

3.项目缺点

  • UDP丢包问题
  • 如果是quit报文丢失了怎么办
  • 性能问题,数据池被打满
  • 可以加入超时重传(如果接受缓冲区打满会出现很大的问题)

4. 项目扩展

  • 管理客户(超时间断开连接)
  • 模拟注册功能
  • 模拟登录过程
  • 基于ncurses库实现点击在线列表中的好友进行单聊

5.为什么采用UDP而不是TCP

  • 因为群聊系统强调实时性要强,如果使用TCP,就要经过漫长的三次握手和四次挥手
  • TCP需要建立连接,网络开销比较大
  • UDP是不可靠连接,它的效率高,速度快,占用的资源较少,但是不可靠
  • 可以在上层协议中加入一些可靠机制来保证可靠性,UDP是可以扩展的
  • 如果是数量级的连接,UDP的优势是很明显的,如果是TCP协议,服务端需要耗费很高的资源来维持连接

参考链接:https://blog.csdn.net/junjunba2689/article/details/82593124

udpchatsystem's People

Contributors

hansionz avatar

Stargazers

QiaoBa avatar  avatar  avatar

Watchers

James Cloos avatar

Forkers

lattic

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.