linux_qq

所属分类:其他
开发工具:LINUX
文件大小:41KB
下载次数:6
上传日期:2017-11-14 12:07:28
上 传 者零下10度C
说明:  该代码在Linux实现了一个类似于windows上的QQ的聊天工具。主要是基于TCP/IP协议的socket通信。包括服务器端和客户端两部分,其中客户端使用了select的IO多路复用技术,服务器端由于要监听多个客户端,因此使用了epoll的IO多路复用技术。整个项目目前可以实现的功能有用户的注册与登录,添加好友,发送聊天消息,发送与接收文件等。
(The code implements a chat tool similar to windows on QQ in Linux. Socket communication is mainly based on TCP/IP protocol. Including server and client two parts, in which the client uses the select IO multiplexing technology, the server side to monitor a number of clients, so the use of epoll IO multiplexing technology. The functions of the whole project can be registered and logged by users, add friends, send chat messages, send and receive files, etc..)

文件列表:
linux_qq\client\client.cpp (19993, 2017-09-12)
linux_qq\client\fsocket.cpp (5267, 2017-08-11)
linux_qq\client\fsocket.h (4285, 2017-08-10)
linux_qq\client\makefile (575, 2015-08-27)
linux_qq\client\user_input_util.cpp (3542, 2015-08-27)
linux_qq\client\user_input_util.h (1198, 2017-08-02)
linux_qq\const.cpp (1379, 2015-08-27)
linux_qq\const.h (3468, 2015-08-27)
linux_qq\images\cxjg.png (16664, 2015-08-27)
linux_qq\msg_buffer.cpp (3683, 2017-08-10)
linux_qq\msg_buffer.h (3061, 2017-08-10)
linux_qq\msg_util.cpp (1767, 2017-09-08)
linux_qq\msg_util.h (2013, 2017-08-01)
linux_qq\ring_queue.cpp (1914, 2017-08-01)
linux_qq\ring_queue.h (958, 2017-08-01)
linux_qq\server\db.cpp (804, 2017-08-02)
linux_qq\server\db.h (1194, 2015-08-27)
linux_qq\server\friendship (50, 2015-08-27)
linux_qq\server\makefile (434, 2015-08-27)
linux_qq\server\registed (32, 2015-08-27)
linux_qq\server\server.cpp (9619, 2017-08-02)
linux_qq\server\service.cpp (7400, 2017-08-11)
linux_qq\server\service.h (2889, 2017-08-02)
linux_qq\util.cpp (2264, 2017-08-01)
linux_qq\util.h (2005, 2015-08-27)
linux_qq\client (0, 2017-11-14)
linux_qq\images (0, 2017-11-14)
linux_qq\server (0, 2017-11-14)
linux_qq (0, 2017-11-14)

#linux_qq 运行于linux上的命令行即时通讯程序
###编译运行 * 编译
* 进入`client`和`server`目录,分别运行`make`
* 运行
* 首先运行`server`, 进入`server`目录, 运行命令`./server`
* 再运行`client`, 进入`client`目录, 运行命令`./client xx.xx.xx.xx`
* `xx.xx.xx.xx`代表`服务器程序所在机器的ip地址`
###已有功能 * [注册]
* 运行客户端,选择`1`,按照提示输入`用户名`和`密码`
* [登录]
* 运行客户端,选择`0`,按照提示输入`用户名`和`密码`
* [发送消息]
* 请按照这个格式发送你的消息`to:对方的用户名:消息内容`
* `to`代表发送消息命令
* `:`是英文冒号,作为分隔符
* [发送文件]
* 命令格式为`fto:对方的用户名:文件路径`
* `fto`代表请求发送文件命令
* `文件路径`必须是合法的unix文件路径形式,例如:`/home/wugui/data`或`../data`
* 该命令支持`目录传输`
* [同意接收文件]
* 首先进入`client`目录,建立接收文件的根目录:`mkdir data`
* 命令格式为`fok:文件发送方的用户名:文件名`
* 接收到的文件存放在`client/data/`目录下
* 如果待接收的文件已经在data目录下,将导致接收失败
* [拒绝接收文件]
* 命令格式为`fno:文件发送方的用户名:文件名`
* [查看好友列表]
* 命令`list`
* [请求添加好友]
* 命令格式`add:用户名`
* [同意添加好友]
* 命令格式`addok:请求方的用户名`
* [拒绝添加好友]
* 命令格式`addno:请求方的用户名`
###代码文件功能 * `msg_buffer.h`定义了向socket写入消息和从socket读出消息的缓冲队列
* `util.h`声明了创建socket,设置epoll_event的帮助函数
* `msg_util.h`定义了封装消息和拆解消息的接口
* `ring_queue.h`定义了用于生产者-消费者问题的循环队列
* `const.h`声明了所有常量
* `server/`目录
* `server.cpp`包含了服务器的逻辑实现,添加新功能只需要修改do_service()函数和service.h中对应的接口即可
* `service.h`定义了服务器程序的服务接口
* `db.h`定义了服务器需要使用的表,这些表用来模拟数据库表
* `registed`文件保存了注册用户信息
* `friendship`文件保存了好友关系
* `client/`目录
* `user_input_util.h`定义了提取用户输入的接口
* `fsocket.h`定义了传输文件的接口.文件传输的过程与tcp协议通信过程类似,分成建立连接,文件内容传输,断开连接.
* `client.cpp`包含了客户端的逻辑
* 客户端使用select函数处理三类io事件: 用户输入,网络输入,网络输出
* 开辟子线程负责文件发送或接收
* 文件发送和主线程发送消息是一个`互斥访问`消息缓冲的问题
* 接收文件是一个生产者-消费者问题: 主线程将接收到的文件消息发送到队列,子线程从队列读出消息并将消息内容写入对应文件

近期下载者

相关文件


收藏者