2 Star 1 Fork 0

橘色的喵 / openresty-tcp-server-demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

环境安装(ubuntu)

  • tcp服务

    apt-get install openresty

  • 测试客户端

    • apt-get install lua5.1 luajit

    • luarocks install luaposix

    • 在~/.bashrc文件中添加

    export LUA_PATH="./?.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?.lua;;"
    export LUA_CPATH="./?.so;/usr/local/lib/lua/5.1/?.so;/usr/lib/x86_64-linux-gnu/lua/5.1/?.so;;"

程序运行方法

  • 运行tcp服务方法 ./start.sh

  • 运行测试程序方法

    接着:

    • cd test/stream

    • luajit test_client.lua

tcp通讯协议:

消息 长度(BYTES) 结构 描述
Header 4 SyncBytes 识别码,表示不同设备之间的交互
Header 4 FullMessageLength 数据总长度,包括SyncBytes和FullMessageLength
Header 4 MeaageType 消息类型(消息号),如登录消息或发送消息消息
Header 4 StringBody 消息字符流长度
Body StringBodyLength StringBody 消息体长度,可能为0
Body FullMessageLength - 16 - StringBodyLength BinaryData 二进制数据,长度可能为0

注: 消息头总共16个字节(包括SyncBytes和FullMessageLength),消息体长度StringBodyLength是已知的,而二进制数据长度计算得到(FullMessageLength - 16 - StringBodyLength)。

测试程序内容

  • 1、客户端向服务端发送请求(req),服务端回复(res);
  • 2、服务端定时检测客户端发送过来的心跳包,超过60s未有心跳包认为客户端断链;
  • 3、客户端向服务端推送消息;
  • 4、服务端主动想客户端推送消息。
MIT License Copyright (c) 2022 stallion5632 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于openresty的tcp服务框架以及lua测试程序 展开 收起
Lua 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/liudegui/openresty-tcp-server-demo.git
git@gitee.com:liudegui/openresty-tcp-server-demo.git
liudegui
openresty-tcp-server-demo
openresty-tcp-server-demo
master

搜索帮助