Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

MsgTrans for rust, support multiple protocol create server and client, protocol support TCP / QUIC / WEBSOCKET.

License

NotificationsYou must be signed in to change notification settings

zoujiaqing/msgtrans-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Server sample code

Using MsgTrans to create multiple protocol server.

letmut server =MessageTransportServer::new();// Add TCP channelserver.add_channel(TcpServerChannel::new("0.0.0.0",9001)).await;// Add WebSocket channelserver.add_channel(WebSocketServerChannel::new("0.0.0.0",9002,"/ws")).await;// Add QUIC channelserver.add_channel(QuicServerChannel::new("0.0.0.0",9003,"certs/cert.pem","certs/key.pem",)).await;// set some callback handler for serverserver.start().await;

Run example for server

cargo run --example server

Run example for client

# for tcpcargo run --example client_tcp# for websocketcargo run --example client_websocket# for quiccargo run --example client_quic

Generate cert and key for test

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

Packet Structure

+--------------------------------+|         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.

About

MsgTrans for rust, support multiple protocol create server and client, protocol support TCP / QUIC / WEBSOCKET.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp