-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tanghuayu
committed
May 28, 2024
0 parents
commit 03c4839
Showing
9 changed files
with
573 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "tiny-agent" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
clap = { version = "4.5.4", features = ["derive"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# TINY AGENT | ||
|
||
一个小型的agent,可以作为socket服务端,也可以作为socket客户端 | ||
无论是客户端还是服务端都将收到的消息作为子进程命令行执行 | ||
|
||
## 使用方法 | ||
``` | ||
Usage: tiny-agent [OPTIONS] --server-ip <SERVER_IP> | ||
Options: | ||
--server | ||
当前agent作为socket服务端,默认作为服务端 | ||
--client | ||
当前agent作为socket客户端 | ||
--server-port <SERVER_PORT> | ||
作为服务端是socket监听端口,作为客户端是服务端的连接端口,默认8080 [default: 8080] | ||
--server-ip <SERVER_IP> | ||
服务端IP地址 | ||
--heartbeat | ||
是否带socket心跳,默认不带 | ||
--heartbeat-interval <HEARTBEAT_INTERVAL> | ||
socket心跳间隔,默认10000毫秒 [default: 10000] | ||
--heartbeat-timeout <HEARTBEAT_TIMEOUT> | ||
socket心跳超时时长,默认30000毫秒 [default: 30000] | ||
--offline-retry | ||
作为客户端时socket是否带掉线重试机制,默认不带 | ||
--offline-retry-interval <OFFLINE_RETRY_INTERVAL> | ||
作为客户端时socket掉线重试机制间隔,默认30000毫秒 [default: 30000] | ||
``` | ||
|
||
## socket服务调试 | ||
|
||
可以使用如下命令快速创建一个socket服务: | ||
``` | ||
tiny-agent --server-ip 127.0.0.1 | ||
``` | ||
|
||
接着使用nc或telnet进行调试 | ||
``` | ||
nc localhost 8080 | ||
ls | ||
pwd | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use clap::Parser; | ||
|
||
/// 一个小型的agent,可以作为socket服务端,也可以作为socket客户端 | ||
/// 无论是客户端还是服务端都将收到的消息作为子进程命令行执行 | ||
#[derive(Parser, Clone, Debug)] | ||
#[command(version, about, long_about = None)] | ||
pub struct Args { | ||
/// 当前agent作为socket服务端,默认作为服务端 | ||
#[arg(long, default_value_t = true)] | ||
pub server: bool, | ||
|
||
/// 当前agent作为socket客户端 | ||
#[arg(long)] | ||
pub client: bool, | ||
|
||
/// 作为服务端是socket监听端口,作为客户端是服务端的连接端口,默认8080 | ||
#[arg(long, default_value_t = 8080)] | ||
pub server_port: u16, | ||
|
||
/// 服务端IP地址 | ||
#[arg(long)] | ||
pub server_ip: String, | ||
|
||
/// 是否带socket心跳,默认不带 | ||
#[arg(long)] | ||
pub heartbeat: bool, | ||
|
||
/// socket心跳间隔,默认10000毫秒 | ||
#[arg(long, default_value = "10000")] | ||
pub heartbeat_interval: u128, | ||
|
||
/// socket心跳超时时长,默认30000毫秒 | ||
#[arg(long, default_value = "30000")] | ||
pub heartbeat_timeout: u128, | ||
|
||
/// 作为客户端时socket是否带掉线重试机制,默认不带 | ||
#[arg(long)] | ||
pub offline_retry: bool, | ||
|
||
/// 作为客户端时socket掉线重试机制间隔,默认30000毫秒 | ||
#[arg(long, default_value = "30000")] | ||
pub offline_retry_interval: u128, | ||
} |
Oops, something went wrong.