Skip to content

Commit

Permalink
init code
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghuayu committed May 28, 2024
0 parents commit 03c4839
Show file tree
Hide file tree
Showing 9 changed files with 573 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
237 changes: 237 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
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"] }
44 changes: 44 additions & 0 deletions README.md
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
...
```
43 changes: 43 additions & 0 deletions src/args.rs
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,
}
Loading

0 comments on commit 03c4839

Please sign in to comment.