Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ tls = true # If `true` then it will use settings in `server.transport.tls`
type = "tcp" # Optional. Same as the client `[client.services.X.type]
token = "whatever" # Necessary if `server.default_token` not set
bind_addr = "0.0.0.0:8081" # Necessary. The address of the service is exposed at. Generally only the port needs to be change.
max_clients = 10 # Optional. 限制此服务的并发连接数。默认值:无限制
nodelay = true # Optional. Same as the client

[server.services.service2]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ tls = true # If `true` then it will use settings in `server.transport.tls`
type = "tcp" # Optional. Same as the client `[client.services.X.type]
token = "whatever" # Necessary if `server.default_token` not set
bind_addr = "0.0.0.0:8081" # Necessary. The address of the service is exposed at. Generally only the port needs to be change.
max_clients = 10 # Optional. Limit the number of concurrent connections for this service. Default: unlimited
nodelay = true # Optional. Same as the client

[server.services.service2]
Expand Down
6 changes: 6 additions & 0 deletions examples/max_clients/client.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[client]
remote_addr = "127.0.0.1:2333"
default_token = "simple_test"

[client.services.test_service]
local_addr = "127.0.0.1:8888"
9 changes: 9 additions & 0 deletions examples/max_clients/server.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[server]
bind_addr = "0.0.0.0:2333"
default_token = "simple_test"
heartbeat_interval = 10

# Simple test with single client limit
[server.services.test_service]
bind_addr = "0.0.0.0:5555"
max_clients = 1
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ pub struct ServerServiceConfig {
pub bind_addr: String,
pub token: Option<MaskedString>,
pub nodelay: Option<bool>,
/// Maximum number of concurrent client connections allowed for this service.
/// None or 0 means unlimited connections (default behavior).
pub max_clients: Option<usize>,
}

impl ServerServiceConfig {
Expand Down
2 changes: 2 additions & 0 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum Ack {
Ok,
ServiceNotExist,
AuthFailed,
ServiceAtFullCapacity,
}

impl std::fmt::Display for Ack {
Expand All @@ -41,6 +42,7 @@ impl std::fmt::Display for Ack {
Ack::Ok => "Ok",
Ack::ServiceNotExist => "Service not exist",
Ack::AuthFailed => "Incorrect token",
Ack::ServiceAtFullCapacity => "Service at maximum capacity (max_clients limit reached)",
}
)
}
Expand Down
Loading
Loading