MsgTrans 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
MsgTrans 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
MsgTrans 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 Apache
开发语言 Rust
操作系统 跨平台
软件类型 开源软件
所属分类 程序开发网络工具包
开源组织
地区 国产
投 递 者 zoujiaqing
适用人群 未知
收录时间 2024-09-11

软件简介

MsgTrans是一个可同时监听多协议的网络框架,消息头采用二进制协议,兼容 Rust / D语言 / Typescript / C++ / Java 等语言,业务逻辑层只需要编写一套即可。

服务端示例代码

let mut server = MessageTransportServer::new();

// Add TCP channel
server.add_channel(TcpServerChannel::new("0.0.0.0", 9001)).await;

// Add WebSocket channel
server.add_channel(WebSocketServerChannel::new("0.0.0.0", 9002, "/ws")).await;

// Add QUIC channel
server.add_channel(QuicServerChannel::new(
    "0.0.0.0",
    9003,
    "certs/cert.pem",
    "certs/key.pem",
)).await;

// set some callback handler for server

server.start().await;

运行示例代码

cargo run --example server

客户端示例代码

# for tcp
cargo run --example client_tcp
# for websocket
cargo run --example client_websocket
# for quic
cargo run --example client_quic

生成秘钥

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365000 -nodes -subj "/CN=localhost"

消息包xie'y

+--------------------------------+
|         Packet Header          |
|  +--------------------------+  |
|  |  Message ID (4 bytes)    |  |
|  +--------------------------+  |
|  |  Message Length (4 bytes)|  |
|  +--------------------------+  |
|  | Compression Type (1 byte)|  |
|  +--------------------------+  |
|  |  Extend Length (4 bytes) |  |
|  +--------------------------+  |
|  |  Reserved (3 bytes)      |  |
|  +--------------------------+  |
+--------------------------------+
              |
              v
+--------------------------------+
|    Extended Header Content     |
|  (variable length, Extend      |
|   Length specifies size)       |
+--------------------------------+
              |
              v
+--------------------------------+
|        Payload Content         |
|    (variable length, Message   |
|     Length specifies size)     |
+--------------------------------+

协议结构说明:

  1. Header Content: Contains fixed-length header information, including Message ID, Message Length, Compression Type, and Extend Length.
  2. Extended Header Content: Variable-length extended header content, with its size specified by the Extend Length field.
  3. Payload Content: Variable-length payload content, with its size specified by the Message Length field.
展开阅读全文

代码

的 Gitee 指数为
超过 的项目

评论

点击加入讨论🔥(8) 发布并加入讨论🔥
暂无内容
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
8 评论
2 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部