Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zoujiaqing/msgtrans-rust
MsgTrans for rust, support multiple protocol create server and client, protocol support TCP / QUIC / WEBSOCKET.
https://github.com/zoujiaqing/msgtrans-rust
network quic quic-client quic-server socket tcp tcp-client tcp-server websocket websocket-client websocket-server
Last synced: 2 days ago
JSON representation
MsgTrans for rust, support multiple protocol create server and client, protocol support TCP / QUIC / WEBSOCKET.
- Host: GitHub
- URL: https://github.com/zoujiaqing/msgtrans-rust
- Owner: zoujiaqing
- License: apache-2.0
- Created: 2024-08-10T17:18:08.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-11-11T19:39:40.000Z (2 months ago)
- Last Synced: 2024-12-12T16:42:03.887Z (about 1 month ago)
- Topics: network, quic, quic-client, quic-server, socket, tcp, tcp-client, tcp-server, websocket, websocket-client, websocket-server
- Language: Rust
- Homepage:
- Size: 186 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MsgTrans for rust
## Server sample code
Using MsgTrans to create multiple protocol server.
```rust
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;
```## Run example for server
```bash
cargo run --example server
```## Run example for client
```bash
# for tcp
cargo run --example client_tcp
# for websocket
cargo run --example client_websocket
# for quic
cargo run --example client_quic
```## Generate cert and key for test
```bash
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365000 -nodes -subj "/CN=localhost"
```## Packet Structure
```text
+--------------------------------+
| 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) |
+--------------------------------+
```Structure Explanation:
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.