Crate msg_transmitter[][src]

msg-transmitter

Overview

It is a library of single server multiple clients model. The main purpose of this library is helping users more focus on communication logic instead of low-level networking design. User can transmit any structs between server and client.

dependances

  • Main networking architecture impletmented by asynchronous framework tokio and futures.

  • User data are transfered to bytes by serialization framework serde and binary encoder/decoder crate bincode.

example

Examples can be found here.

Design

For server, when start_server is called, it will start binding and listening the target port and spawning two tokio-style tasks for each socket. One task for receiving message from socket and processing user's logic, another task for sending message to socket. After the first task processes user's logic, it will send message to another task through mpsc::channel.

For client, when start_client is called, it will start connecting the target port and creating a socket, sending register information (a name presented by String), spawning two tokio-style tasks for each socket. Two tasks work with each other by the same way as server tasks do. For now, all our networking is based on TCP. All user data are transferred to bytes through a simple protocol.

+++++++++++++++++++++++++++++++++++++++++++++++ Data_size(4 bytes) | State(1 byte) | Data +++++++++++++++++++++++++++++++++++++++++++++++

Data_size is a 4-bytes head to represent the number of bytes of state and Data. So each stream can't transmit message which contains more than 2^32 bytes data.

State represents the state of this stream, it just has two states for now. When state equals 0, the data is register informaiton; when state equals 1, the data is user's message.

This crate is created by ChijinZ(tlock.chijin@gmail.com).

Structs

MsgClient
MsgServer

Functions

four_vecu8_to_number
number_to_four_vecu8