Crate tcp_client
source ·Expand description
§Tcp-Client
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.1"
§Example
use tcp_client::client_base::ClientBase;
use tcp_client::client_factory;
use tcp_client::ClientFactory;
use tcp_client::network::NetworkError;
client_factory!(MyClientFactory, MyClient, "MyTcpApplication");
impl MyClient {
// define your method here.
// example:
async fn my_method(&mut self) -> Result<(), NetworkError> {
self.check_func("my_method").await?;
// ...
Ok(())
}
}
#[tokio::main]
async fn main() {
let mut client = MyClientFactory.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.1.0 | >=0.2.0 |
<0.1.0 | <0.2.0 |
Re-exports§
pub extern crate tcp_handler;
pub extern crate tokio;
Modules§
- The basic trait for client.
- Global configuration for this crate.
- A wrapper for
AesCipher
to make it easier to update. - Some network utility functions.
Macros§
- Conveniently define a client factory.
Traits§
- The client factory to create clients.
Functions§
- A shortcut for
ClientFactory
.