9 releases

0.2.0 Mar 21, 2024
0.1.1 Jan 27, 2024
0.0.6 Jan 9, 2024

#1855 in Network programming

Download history 17/week @ 2023-12-30 27/week @ 2024-01-06 12/week @ 2024-01-20 7/week @ 2024-01-27 2/week @ 2024-02-24 2/week @ 2024-03-09 116/week @ 2024-03-16 19/week @ 2024-03-23 20/week @ 2024-03-30 22/week @ 2024-04-06

178 downloads per month
Used in tcp-server

MIT/Apache

130KB
1.5K SLoC

Tcp-Client

Crate Crates.io License

Read this in other languages: English, 简体中文.

Description

Convenient client-side TCP service. Also see tcp-server for server-side.

Based on tcp-handler.

With complete API document.

Usage

Add this to your Cargo.toml:

[dependencies]
tcp-client = "~0.2"

Example

use tcp_client::define_client;
use tcp_client::errors::Result;

define_client!(pub CommonMyClient, MyClient, "MyTcpApplication");

impl MyClient {
    // define your method here.
    // example:
    async fn my_method(&mut self) -> Result<()> {
        self.check_func("my_method").await?;
        // ...
        Ok(())
    }
}

#[tokio::main]
async fn main() {
    let mut client = MyClient::connect("127.0.0.1:1234").await.unwrap();
    // use client.
    // example:
    client.my_method().await.unwrap();
}

Version map

Versions map to tcp-server with the same protocol. (Recommended for use in conjunction, otherwise unexpected bugs may occur.)

client version server version
>=0.2.0 >=0.3.0
<0.2.0, >=0.1.0 <0.3.0 >=0.2.0
<0.1.0 <0.2.0

License

Licensed under either of

at your option.

Dependencies

~3–15MB
~172K SLoC