1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//! # Lynn_tcp
//! `Lynn_tcp` is a lightweight TCP server framework
//! ## Keywords
//! **Lightweight**: concise code that is easier to learn and use
//!
//! **Concurrent and Performance**: Based on Tokio's excellent asynchronous performance, it is easy to achieve concurrent processing capabilities for multi-user links
//!
//! **Lower latency**: Design with read and write separation to achieve lower latency
//!
//! **Security**: Code written with strong typing and memory safety in Rust
//! ## Features
//! - **server**: Provide customizable TCP services that can easily achieve multi-user long connections and concurrent processing capabilities, with services for different routes
//! - **client**: Provides a custom TCP client that sends and receives messages to and from a TCP server
//! ## Server
//! Represents a server for the Lynn application.
//!
//! The `LynnServer` struct holds information about the server, including its configuration,
//! client list, router map, and thread pool.
//!
//! ### Example
//! Use default config
//! ```rust
//! use lynn_tcp::{lynn_server::*, lynn_tcp_dependents::*};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let _ = LynnServer::new()
//! .await
//! .add_router(1, my_service)
//! .add_router(2, my_service_with_buf)
//! .add_router(3, my_service_with_clients)
//! .start()
//! .await;
//! Ok(())
//! }
//!
//! pub async fn my_service() -> HandlerResult {
//! HandlerResult::new_without_send()
//! }
//! pub async fn my_service_with_buf(input_buf_vo: InputBufVO) -> HandlerResult {
//! println!(
//! "service read from :{}",
//! input_buf_vo.get_input_addr().unwrap()
//! );
//! HandlerResult::new_without_send()
//! }
//! pub async fn my_service_with_clients(clients_context: ClientsContext) -> HandlerResult {
//! HandlerResult::new_with_send(1, "hello lynn".into(), clients_context.get_all_clients_addrs().await)
//! }
//! ```
//! ### Example
//! Use customized config
//! ```rust
//! use lynn_tcp::{lynn_server::*, lynn_tcp_dependents::*};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let _ = LynnServer::new_with_config(
//! LynnServerConfigBuilder::new()
//! .with_server_ipv4("0.0.0.0:9177")
//! .with_server_max_connections(Some(&200))
//! .with_server_max_threadpool_size(&10)
//! // ...more
//! .build(),
//! )
//! .await
//! .add_router(1, my_service)
//! .add_router(2, my_service_with_buf)
//! .add_router(3, my_service_with_clients)
//! .start()
//! .await;
//! Ok(())
//! }
//!
//! pub async fn my_service() -> HandlerResult {
//! HandlerResult::new_without_send()
//! }
//! pub async fn my_service_with_buf(input_buf_vo: InputBufVO) -> HandlerResult {
//! println!(
//! "service read from :{}",
//! input_buf_vo.get_input_addr().unwrap()
//! );
//! HandlerResult::new_without_send()
//! }
//! pub async fn my_service_with_clients(clients_context: ClientsContext) -> HandlerResult {
//! HandlerResult::new_with_send(1, "hello lynn".into(), clients_context.get_all_clients_addrs().await)
//! }
//! ```
//! ## Clinet
//! A client for communicating with a server over TCP.
//!
//! The `LynnClient` struct represents a client that can connect to a server, send data, and receive data.
//! It uses a configuration object to specify the server's IP address and other settings.
//! The client runs in a separate task and uses channels to communicate with the main task.
//! ### Example
//! Use default config (If you want to use custom configuration, please use `LynnClientConfigBuilder`)
//! ```rust
//! use lynn_tcp::{
//! lynn_client::LynnClient,
//! lynn_tcp_dependents::*,
//! };
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = LynnClient::new_with_ipv4("127.0.0.1:9177")
//! .await
//! .start()
//! .await;
//! let _ = client.send_data(HandlerResult::new_with_send_to_server(1, "hello".into())).await;
//! let input_buf_vo = client.get_receive_data().await.unwrap();
//! Ok(())
//! }
//! ```
/// The application module, containing the server configuration API and server implementation.
/// The client module, containing the client configuration and client implementation.
/// The constant configuration module, containing constants used throughout the application.
/// The DTO factory module, responsible for creating data transfer objects.
/// The handler module, containing the implementation of request handlers.
/// The macros module, containing custom macros used throughout the application.
/// The VO factory module, responsible for creating value objects.
pub extern crate bytes;
pub extern crate tokio;
pub extern crate tracing;
pub extern crate tracing_subscriber;
/// The server module, containing the server configuration API and server implementation.
/// The TCP dependents module, containing common types used by both the server and client.
/// The client module, containing the client configuration and client implementation.