@@ -17,6 +17,17 @@ version = "2.0.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" | checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" | ||||
[[package]] | |||||
name = "ahash" | |||||
version = "0.7.8" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" | |||||
dependencies = [ | |||||
"getrandom 0.2.15", | |||||
"once_cell", | |||||
"version_check", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "async-trait" | name = "async-trait" | ||||
version = "0.1.88" | version = "0.1.88" | ||||
@@ -49,12 +60,24 @@ dependencies = [ | |||||
"windows-targets", | "windows-targets", | ||||
] | ] | ||||
[[package]] | |||||
name = "base64" | |||||
version = "0.13.1" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" | |||||
[[package]] | [[package]] | ||||
name = "base64" | name = "base64" | ||||
version = "0.22.1" | version = "0.22.1" | ||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" | checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" | ||||
[[package]] | |||||
name = "bitflags" | |||||
version = "1.3.2" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" | |||||
[[package]] | [[package]] | ||||
name = "bitflags" | name = "bitflags" | ||||
version = "2.9.0" | version = "2.9.0" | ||||
@@ -94,6 +117,25 @@ version = "1.0.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | ||||
[[package]] | |||||
name = "config" | |||||
version = "0.13.4" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "23738e11972c7643e4ec947840fc463b6a571afcd3e735bdfce7d03c7a784aca" | |||||
dependencies = [ | |||||
"async-trait", | |||||
"json5", | |||||
"lazy_static", | |||||
"nom", | |||||
"pathdiff", | |||||
"ron", | |||||
"rust-ini", | |||||
"serde", | |||||
"serde_json", | |||||
"toml", | |||||
"yaml-rust", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "cpufeatures" | name = "cpufeatures" | ||||
version = "0.2.17" | version = "0.2.17" | ||||
@@ -124,6 +166,12 @@ dependencies = [ | |||||
"subtle", | "subtle", | ||||
] | ] | ||||
[[package]] | |||||
name = "dlv-list" | |||||
version = "0.3.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" | |||||
[[package]] | [[package]] | ||||
name = "fallible-iterator" | name = "fallible-iterator" | ||||
version = "0.2.0" | version = "0.2.0" | ||||
@@ -194,6 +242,17 @@ dependencies = [ | |||||
"version_check", | "version_check", | ||||
] | ] | ||||
[[package]] | |||||
name = "getrandom" | |||||
version = "0.2.15" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" | |||||
dependencies = [ | |||||
"cfg-if", | |||||
"libc", | |||||
"wasi 0.11.0+wasi-snapshot-preview1", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "getrandom" | name = "getrandom" | ||||
version = "0.3.2" | version = "0.3.2" | ||||
@@ -212,6 +271,15 @@ version = "0.31.1" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" | checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" | ||||
[[package]] | |||||
name = "hashbrown" | |||||
version = "0.12.3" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" | |||||
dependencies = [ | |||||
"ahash", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "hmac" | name = "hmac" | ||||
version = "0.12.1" | version = "0.12.1" | ||||
@@ -221,6 +289,12 @@ dependencies = [ | |||||
"digest", | "digest", | ||||
] | ] | ||||
[[package]] | |||||
name = "itoa" | |||||
version = "1.0.15" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" | |||||
[[package]] | [[package]] | ||||
name = "js-sys" | name = "js-sys" | ||||
version = "0.3.77" | version = "0.3.77" | ||||
@@ -231,12 +305,35 @@ dependencies = [ | |||||
"wasm-bindgen", | "wasm-bindgen", | ||||
] | ] | ||||
[[package]] | |||||
name = "json5" | |||||
version = "0.4.1" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" | |||||
dependencies = [ | |||||
"pest", | |||||
"pest_derive", | |||||
"serde", | |||||
] | |||||
[[package]] | |||||
name = "lazy_static" | |||||
version = "1.5.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" | |||||
[[package]] | [[package]] | ||||
name = "libc" | name = "libc" | ||||
version = "0.2.172" | version = "0.2.172" | ||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" | checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" | ||||
[[package]] | |||||
name = "linked-hash-map" | |||||
version = "0.5.6" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" | |||||
[[package]] | [[package]] | ||||
name = "lock_api" | name = "lock_api" | ||||
version = "0.4.12" | version = "0.4.12" | ||||
@@ -269,6 +366,12 @@ version = "2.7.4" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" | checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" | ||||
[[package]] | |||||
name = "minimal-lexical" | |||||
version = "0.2.1" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" | |||||
[[package]] | [[package]] | ||||
name = "miniz_oxide" | name = "miniz_oxide" | ||||
version = "0.8.8" | version = "0.8.8" | ||||
@@ -289,6 +392,16 @@ dependencies = [ | |||||
"windows-sys", | "windows-sys", | ||||
] | ] | ||||
[[package]] | |||||
name = "nom" | |||||
version = "7.1.3" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" | |||||
dependencies = [ | |||||
"memchr", | |||||
"minimal-lexical", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "object" | name = "object" | ||||
version = "0.36.7" | version = "0.36.7" | ||||
@@ -304,6 +417,16 @@ version = "1.21.3" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" | checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" | ||||
[[package]] | |||||
name = "ordered-multimap" | |||||
version = "0.4.3" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" | |||||
dependencies = [ | |||||
"dlv-list", | |||||
"hashbrown", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "parking_lot" | name = "parking_lot" | ||||
version = "0.12.3" | version = "0.12.3" | ||||
@@ -327,12 +450,63 @@ dependencies = [ | |||||
"windows-targets", | "windows-targets", | ||||
] | ] | ||||
[[package]] | |||||
name = "pathdiff" | |||||
version = "0.2.3" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" | |||||
[[package]] | [[package]] | ||||
name = "percent-encoding" | name = "percent-encoding" | ||||
version = "2.3.1" | version = "2.3.1" | ||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" | checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" | ||||
[[package]] | |||||
name = "pest" | |||||
version = "2.8.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "198db74531d58c70a361c42201efde7e2591e976d518caf7662a47dc5720e7b6" | |||||
dependencies = [ | |||||
"memchr", | |||||
"thiserror", | |||||
"ucd-trie", | |||||
] | |||||
[[package]] | |||||
name = "pest_derive" | |||||
version = "2.8.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "d725d9cfd79e87dccc9341a2ef39d1b6f6353d68c4b33c177febbe1a402c97c5" | |||||
dependencies = [ | |||||
"pest", | |||||
"pest_generator", | |||||
] | |||||
[[package]] | |||||
name = "pest_generator" | |||||
version = "2.8.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "db7d01726be8ab66ab32f9df467ae8b1148906685bbe75c82d1e65d7f5b3f841" | |||||
dependencies = [ | |||||
"pest", | |||||
"pest_meta", | |||||
"proc-macro2", | |||||
"quote", | |||||
"syn", | |||||
] | |||||
[[package]] | |||||
name = "pest_meta" | |||||
version = "2.8.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "7f9f832470494906d1fca5329f8ab5791cc60beb230c74815dff541cbd2b5ca0" | |||||
dependencies = [ | |||||
"once_cell", | |||||
"pest", | |||||
"sha2", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "phf" | name = "phf" | ||||
version = "0.11.3" | version = "0.11.3" | ||||
@@ -369,7 +543,7 @@ version = "0.6.8" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "76ff0abab4a9b844b93ef7b81f1efc0a366062aaef2cd702c76256b5dc075c54" | checksum = "76ff0abab4a9b844b93ef7b81f1efc0a366062aaef2cd702c76256b5dc075c54" | ||||
dependencies = [ | dependencies = [ | ||||
"base64", | |||||
"base64 0.22.1", | |||||
"byteorder", | "byteorder", | ||||
"bytes", | "bytes", | ||||
"fallible-iterator", | "fallible-iterator", | ||||
@@ -451,7 +625,7 @@ version = "0.9.3" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" | checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" | ||||
dependencies = [ | dependencies = [ | ||||
"getrandom", | |||||
"getrandom 0.3.2", | |||||
] | ] | ||||
[[package]] | [[package]] | ||||
@@ -460,7 +634,28 @@ version = "0.5.11" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3" | checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3" | ||||
dependencies = [ | dependencies = [ | ||||
"bitflags", | |||||
"bitflags 2.9.0", | |||||
] | |||||
[[package]] | |||||
name = "ron" | |||||
version = "0.7.1" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a" | |||||
dependencies = [ | |||||
"base64 0.13.1", | |||||
"bitflags 1.3.2", | |||||
"serde", | |||||
] | |||||
[[package]] | |||||
name = "rust-ini" | |||||
version = "0.18.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" | |||||
dependencies = [ | |||||
"cfg-if", | |||||
"ordered-multimap", | |||||
] | ] | ||||
[[package]] | [[package]] | ||||
@@ -469,12 +664,50 @@ version = "0.1.24" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" | checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" | ||||
[[package]] | |||||
name = "ryu" | |||||
version = "1.0.20" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" | |||||
[[package]] | [[package]] | ||||
name = "scopeguard" | name = "scopeguard" | ||||
version = "1.2.0" | version = "1.2.0" | ||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" | checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" | ||||
[[package]] | |||||
name = "serde" | |||||
version = "1.0.219" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" | |||||
dependencies = [ | |||||
"serde_derive", | |||||
] | |||||
[[package]] | |||||
name = "serde_derive" | |||||
version = "1.0.219" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" | |||||
dependencies = [ | |||||
"proc-macro2", | |||||
"quote", | |||||
"syn", | |||||
] | |||||
[[package]] | |||||
name = "serde_json" | |||||
version = "1.0.140" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" | |||||
dependencies = [ | |||||
"itoa", | |||||
"memchr", | |||||
"ryu", | |||||
"serde", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "sha2" | name = "sha2" | ||||
version = "0.10.8" | version = "0.10.8" | ||||
@@ -558,10 +791,32 @@ dependencies = [ | |||||
name = "tcp_client" | name = "tcp_client" | ||||
version = "0.1.0" | version = "0.1.0" | ||||
dependencies = [ | dependencies = [ | ||||
"config", | |||||
"serde", | |||||
"tokio", | "tokio", | ||||
"tokio-postgres", | "tokio-postgres", | ||||
] | ] | ||||
[[package]] | |||||
name = "thiserror" | |||||
version = "2.0.12" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" | |||||
dependencies = [ | |||||
"thiserror-impl", | |||||
] | |||||
[[package]] | |||||
name = "thiserror-impl" | |||||
version = "2.0.12" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" | |||||
dependencies = [ | |||||
"proc-macro2", | |||||
"quote", | |||||
"syn", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "tinyvec" | name = "tinyvec" | ||||
version = "1.9.0" | version = "1.9.0" | ||||
@@ -645,12 +900,27 @@ dependencies = [ | |||||
"tokio", | "tokio", | ||||
] | ] | ||||
[[package]] | |||||
name = "toml" | |||||
version = "0.5.11" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" | |||||
dependencies = [ | |||||
"serde", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "typenum" | name = "typenum" | ||||
version = "1.18.0" | version = "1.18.0" | ||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" | checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" | ||||
[[package]] | |||||
name = "ucd-trie" | |||||
version = "0.1.7" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" | |||||
[[package]] | [[package]] | ||||
name = "unicode-bidi" | name = "unicode-bidi" | ||||
version = "0.3.18" | version = "0.3.18" | ||||
@@ -862,7 +1132,16 @@ version = "0.39.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" | checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" | ||||
dependencies = [ | dependencies = [ | ||||
"bitflags", | |||||
"bitflags 2.9.0", | |||||
] | |||||
[[package]] | |||||
name = "yaml-rust" | |||||
version = "0.4.5" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" | |||||
dependencies = [ | |||||
"linked-hash-map", | |||||
] | ] | ||||
[[package]] | [[package]] | ||||
@@ -6,3 +6,5 @@ edition = "2021" | |||||
[dependencies] | [dependencies] | ||||
tokio = { version = "1.28", features = ["full"] } | tokio = { version = "1.28", features = ["full"] } | ||||
tokio-postgres = "0.7" | tokio-postgres = "0.7" | ||||
config = "0.13" | |||||
serde = { version = "1.0", features = ["derive"] } |
@@ -0,0 +1,10 @@ | |||||
[server] | |||||
#host = "10.180.4.88" | |||||
host = "127.0.0.1" | |||||
port = 9090 | |||||
[client] | |||||
max_retries = 3 | |||||
retry_delay_secs = 3 | |||||
read_timeout_secs = 5 | |||||
write_timeout_secs = 5 |
@@ -4,22 +4,61 @@ use std::net::TcpStream; | |||||
use std::io::{Read, Write}; | use std::io::{Read, Write}; | ||||
use std::thread; | use std::thread; | ||||
use std::time::Duration; | use std::time::Duration; | ||||
use serde::Deserialize; | |||||
use config::Config; | |||||
#[derive(Debug, Deserialize)] | |||||
struct ServerConfig { | |||||
host: String, | |||||
port: u16, | |||||
} | |||||
#[derive(Debug, Deserialize)] | |||||
struct ClientConfig { | |||||
max_retries: u32, | |||||
retry_delay_secs: u64, | |||||
read_timeout_secs: u64, | |||||
write_timeout_secs: u64, | |||||
} | |||||
#[derive(Debug, Deserialize)] | |||||
struct Settings { | |||||
server: ServerConfig, | |||||
client: ClientConfig, | |||||
} | |||||
fn load_config() -> Result<Settings, config::ConfigError> { | |||||
let settings = Config::builder() | |||||
.add_source(config::File::with_name("config")) | |||||
.build()?; | |||||
settings.try_deserialize() | |||||
} | |||||
#[tokio::main] | #[tokio::main] | ||||
async fn main() { | async fn main() { | ||||
let max_retries = 3; | |||||
// 加载配置 | |||||
let config = match load_config() { | |||||
Ok(cfg) => cfg, | |||||
Err(e) => { | |||||
println!("加载配置文件失败: {}", e); | |||||
return; | |||||
} | |||||
}; | |||||
let mut retry_count = 0; | let mut retry_count = 0; | ||||
let server_addr = format!("{}:{}", config.server.host, config.server.port); | |||||
while retry_count < max_retries { | |||||
println!("尝试连接服务器 (第{}次)...", retry_count + 1); | |||||
while retry_count < config.client.max_retries { | |||||
println!("尝试连接服务器 {} (第{}次)...", server_addr, retry_count + 1); | |||||
match TcpStream::connect("10.180.4.88:9090") { | |||||
match TcpStream::connect(&server_addr) { | |||||
Ok(mut stream) => { | Ok(mut stream) => { | ||||
println!("成功连接到服务器!"); | println!("成功连接到服务器!"); | ||||
// 设置读写超时 | // 设置读写超时 | ||||
stream.set_read_timeout(Some(Duration::from_secs(5))).unwrap(); | |||||
stream.set_write_timeout(Some(Duration::from_secs(5))).unwrap(); | |||||
stream.set_read_timeout(Some(Duration::from_secs(config.client.read_timeout_secs))).unwrap(); | |||||
stream.set_write_timeout(Some(Duration::from_secs(config.client.write_timeout_secs))).unwrap(); | |||||
// 发送数据 | // 发送数据 | ||||
let msg = "HelloOK"; | let msg = "HelloOK"; | ||||
@@ -45,20 +84,20 @@ async fn main() { | |||||
} | } | ||||
Err(e) => println!("接收数据失败: {}", e), | Err(e) => println!("接收数据失败: {}", e), | ||||
} | } | ||||
break; // 如果成功连接并通信,跳出重试循环 | |||||
break; | |||||
} | } | ||||
Err(e) => { | Err(e) => { | ||||
println!("连接服务器失败: {}", e); | println!("连接服务器失败: {}", e); | ||||
retry_count += 1; | retry_count += 1; | ||||
if retry_count < max_retries { | |||||
println!("等待3秒后重试..."); | |||||
thread::sleep(Duration::from_secs(3)); | |||||
if retry_count < config.client.max_retries { | |||||
println!("等待{}秒后重试...", config.client.retry_delay_secs); | |||||
thread::sleep(Duration::from_secs(config.client.retry_delay_secs)); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if retry_count >= max_retries { | |||||
if retry_count >= config.client.max_retries { | |||||
println!("达到最大重试次数,程序退出"); | println!("达到最大重试次数,程序退出"); | ||||
} | } | ||||
} | } |
@@ -17,6 +17,28 @@ version = "2.0.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" | checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" | ||||
[[package]] | |||||
name = "ahash" | |||||
version = "0.7.8" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" | |||||
dependencies = [ | |||||
"getrandom", | |||||
"once_cell", | |||||
"version_check", | |||||
] | |||||
[[package]] | |||||
name = "async-trait" | |||||
version = "0.1.88" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" | |||||
dependencies = [ | |||||
"proc-macro2", | |||||
"quote", | |||||
"syn", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "autocfg" | name = "autocfg" | ||||
version = "1.4.0" | version = "1.4.0" | ||||
@@ -38,12 +60,33 @@ dependencies = [ | |||||
"windows-targets", | "windows-targets", | ||||
] | ] | ||||
[[package]] | |||||
name = "base64" | |||||
version = "0.13.1" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" | |||||
[[package]] | |||||
name = "bitflags" | |||||
version = "1.3.2" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" | |||||
[[package]] | [[package]] | ||||
name = "bitflags" | name = "bitflags" | ||||
version = "2.9.0" | version = "2.9.0" | ||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" | checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" | ||||
[[package]] | |||||
name = "block-buffer" | |||||
version = "0.10.4" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" | |||||
dependencies = [ | |||||
"generic-array", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "bytes" | name = "bytes" | ||||
version = "1.10.1" | version = "1.10.1" | ||||
@@ -56,18 +99,131 @@ version = "1.0.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | ||||
[[package]] | |||||
name = "config" | |||||
version = "0.13.4" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "23738e11972c7643e4ec947840fc463b6a571afcd3e735bdfce7d03c7a784aca" | |||||
dependencies = [ | |||||
"async-trait", | |||||
"json5", | |||||
"lazy_static", | |||||
"nom", | |||||
"pathdiff", | |||||
"ron", | |||||
"rust-ini", | |||||
"serde", | |||||
"serde_json", | |||||
"toml", | |||||
"yaml-rust", | |||||
] | |||||
[[package]] | |||||
name = "cpufeatures" | |||||
version = "0.2.17" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" | |||||
dependencies = [ | |||||
"libc", | |||||
] | |||||
[[package]] | |||||
name = "crypto-common" | |||||
version = "0.1.6" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" | |||||
dependencies = [ | |||||
"generic-array", | |||||
"typenum", | |||||
] | |||||
[[package]] | |||||
name = "digest" | |||||
version = "0.10.7" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" | |||||
dependencies = [ | |||||
"block-buffer", | |||||
"crypto-common", | |||||
] | |||||
[[package]] | |||||
name = "dlv-list" | |||||
version = "0.3.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" | |||||
[[package]] | |||||
name = "generic-array" | |||||
version = "0.14.7" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" | |||||
dependencies = [ | |||||
"typenum", | |||||
"version_check", | |||||
] | |||||
[[package]] | |||||
name = "getrandom" | |||||
version = "0.2.15" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" | |||||
dependencies = [ | |||||
"cfg-if", | |||||
"libc", | |||||
"wasi", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "gimli" | name = "gimli" | ||||
version = "0.31.1" | version = "0.31.1" | ||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" | checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" | ||||
[[package]] | |||||
name = "hashbrown" | |||||
version = "0.12.3" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" | |||||
dependencies = [ | |||||
"ahash", | |||||
] | |||||
[[package]] | |||||
name = "itoa" | |||||
version = "1.0.15" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" | |||||
[[package]] | |||||
name = "json5" | |||||
version = "0.4.1" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" | |||||
dependencies = [ | |||||
"pest", | |||||
"pest_derive", | |||||
"serde", | |||||
] | |||||
[[package]] | |||||
name = "lazy_static" | |||||
version = "1.5.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" | |||||
[[package]] | [[package]] | ||||
name = "libc" | name = "libc" | ||||
version = "0.2.172" | version = "0.2.172" | ||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" | checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" | ||||
[[package]] | |||||
name = "linked-hash-map" | |||||
version = "0.5.6" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" | |||||
[[package]] | [[package]] | ||||
name = "lock_api" | name = "lock_api" | ||||
version = "0.4.12" | version = "0.4.12" | ||||
@@ -84,6 +240,12 @@ version = "2.7.4" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" | checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" | ||||
[[package]] | |||||
name = "minimal-lexical" | |||||
version = "0.2.1" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" | |||||
[[package]] | [[package]] | ||||
name = "miniz_oxide" | name = "miniz_oxide" | ||||
version = "0.8.8" | version = "0.8.8" | ||||
@@ -104,6 +266,16 @@ dependencies = [ | |||||
"windows-sys", | "windows-sys", | ||||
] | ] | ||||
[[package]] | |||||
name = "nom" | |||||
version = "7.1.3" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" | |||||
dependencies = [ | |||||
"memchr", | |||||
"minimal-lexical", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "object" | name = "object" | ||||
version = "0.36.7" | version = "0.36.7" | ||||
@@ -113,6 +285,22 @@ dependencies = [ | |||||
"memchr", | "memchr", | ||||
] | ] | ||||
[[package]] | |||||
name = "once_cell" | |||||
version = "1.21.3" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" | |||||
[[package]] | |||||
name = "ordered-multimap" | |||||
version = "0.4.3" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" | |||||
dependencies = [ | |||||
"dlv-list", | |||||
"hashbrown", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "parking_lot" | name = "parking_lot" | ||||
version = "0.12.3" | version = "0.12.3" | ||||
@@ -136,6 +324,57 @@ dependencies = [ | |||||
"windows-targets", | "windows-targets", | ||||
] | ] | ||||
[[package]] | |||||
name = "pathdiff" | |||||
version = "0.2.3" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" | |||||
[[package]] | |||||
name = "pest" | |||||
version = "2.8.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "198db74531d58c70a361c42201efde7e2591e976d518caf7662a47dc5720e7b6" | |||||
dependencies = [ | |||||
"memchr", | |||||
"thiserror", | |||||
"ucd-trie", | |||||
] | |||||
[[package]] | |||||
name = "pest_derive" | |||||
version = "2.8.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "d725d9cfd79e87dccc9341a2ef39d1b6f6353d68c4b33c177febbe1a402c97c5" | |||||
dependencies = [ | |||||
"pest", | |||||
"pest_generator", | |||||
] | |||||
[[package]] | |||||
name = "pest_generator" | |||||
version = "2.8.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "db7d01726be8ab66ab32f9df467ae8b1148906685bbe75c82d1e65d7f5b3f841" | |||||
dependencies = [ | |||||
"pest", | |||||
"pest_meta", | |||||
"proc-macro2", | |||||
"quote", | |||||
"syn", | |||||
] | |||||
[[package]] | |||||
name = "pest_meta" | |||||
version = "2.8.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "7f9f832470494906d1fca5329f8ab5791cc60beb230c74815dff541cbd2b5ca0" | |||||
dependencies = [ | |||||
"once_cell", | |||||
"pest", | |||||
"sha2", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "pin-project-lite" | name = "pin-project-lite" | ||||
version = "0.2.16" | version = "0.2.16" | ||||
@@ -166,7 +405,28 @@ version = "0.5.11" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3" | checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3" | ||||
dependencies = [ | dependencies = [ | ||||
"bitflags", | |||||
"bitflags 2.9.0", | |||||
] | |||||
[[package]] | |||||
name = "ron" | |||||
version = "0.7.1" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a" | |||||
dependencies = [ | |||||
"base64", | |||||
"bitflags 1.3.2", | |||||
"serde", | |||||
] | |||||
[[package]] | |||||
name = "rust-ini" | |||||
version = "0.18.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" | |||||
dependencies = [ | |||||
"cfg-if", | |||||
"ordered-multimap", | |||||
] | ] | ||||
[[package]] | [[package]] | ||||
@@ -175,12 +435,61 @@ version = "0.1.24" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" | checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" | ||||
[[package]] | |||||
name = "ryu" | |||||
version = "1.0.20" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" | |||||
[[package]] | [[package]] | ||||
name = "scopeguard" | name = "scopeguard" | ||||
version = "1.2.0" | version = "1.2.0" | ||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" | checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" | ||||
[[package]] | |||||
name = "serde" | |||||
version = "1.0.219" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" | |||||
dependencies = [ | |||||
"serde_derive", | |||||
] | |||||
[[package]] | |||||
name = "serde_derive" | |||||
version = "1.0.219" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" | |||||
dependencies = [ | |||||
"proc-macro2", | |||||
"quote", | |||||
"syn", | |||||
] | |||||
[[package]] | |||||
name = "serde_json" | |||||
version = "1.0.140" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" | |||||
dependencies = [ | |||||
"itoa", | |||||
"memchr", | |||||
"ryu", | |||||
"serde", | |||||
] | |||||
[[package]] | |||||
name = "sha2" | |||||
version = "0.10.8" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" | |||||
dependencies = [ | |||||
"cfg-if", | |||||
"cpufeatures", | |||||
"digest", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "signal-hook-registry" | name = "signal-hook-registry" | ||||
version = "1.4.2" | version = "1.4.2" | ||||
@@ -221,9 +530,30 @@ dependencies = [ | |||||
name = "tcp_server" | name = "tcp_server" | ||||
version = "0.1.0" | version = "0.1.0" | ||||
dependencies = [ | dependencies = [ | ||||
"config", | |||||
"tokio", | "tokio", | ||||
] | ] | ||||
[[package]] | |||||
name = "thiserror" | |||||
version = "2.0.12" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" | |||||
dependencies = [ | |||||
"thiserror-impl", | |||||
] | |||||
[[package]] | |||||
name = "thiserror-impl" | |||||
version = "2.0.12" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" | |||||
dependencies = [ | |||||
"proc-macro2", | |||||
"quote", | |||||
"syn", | |||||
] | |||||
[[package]] | [[package]] | ||||
name = "tokio" | name = "tokio" | ||||
version = "1.44.2" | version = "1.44.2" | ||||
@@ -253,12 +583,39 @@ dependencies = [ | |||||
"syn", | "syn", | ||||
] | ] | ||||
[[package]] | |||||
name = "toml" | |||||
version = "0.5.11" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" | |||||
dependencies = [ | |||||
"serde", | |||||
] | |||||
[[package]] | |||||
name = "typenum" | |||||
version = "1.18.0" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" | |||||
[[package]] | |||||
name = "ucd-trie" | |||||
version = "0.1.7" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" | |||||
[[package]] | [[package]] | ||||
name = "unicode-ident" | name = "unicode-ident" | ||||
version = "1.0.18" | version = "1.0.18" | ||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" | checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" | ||||
[[package]] | |||||
name = "version_check" | |||||
version = "0.9.5" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" | |||||
[[package]] | [[package]] | ||||
name = "wasi" | name = "wasi" | ||||
version = "0.11.0+wasi-snapshot-preview1" | version = "0.11.0+wasi-snapshot-preview1" | ||||
@@ -337,3 +694,12 @@ name = "windows_x86_64_msvc" | |||||
version = "0.52.6" | version = "0.52.6" | ||||
source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" | ||||
[[package]] | |||||
name = "yaml-rust" | |||||
version = "0.4.5" | |||||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||||
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" | |||||
dependencies = [ | |||||
"linked-hash-map", | |||||
] |
@@ -5,3 +5,4 @@ edition = "2021" | |||||
[dependencies] | [dependencies] | ||||
tokio = { version = "1.28", features = ["full"] } | tokio = { version = "1.28", features = ["full"] } | ||||
config = "0.13" |
@@ -0,0 +1,3 @@ | |||||
[server] | |||||
address = "127.0.0.1" | |||||
port = 9090 |
@@ -1,19 +1,29 @@ | |||||
use tokio::net::TcpListener; | use tokio::net::TcpListener; | ||||
use tokio::io::{AsyncReadExt, AsyncWriteExt}; | use tokio::io::{AsyncReadExt, AsyncWriteExt}; | ||||
use config::Config; | |||||
fn check_ok_message(message: &[u8]) -> u8 { | fn check_ok_message(message: &[u8]) -> u8 { | ||||
let message_str = String::from_utf8_lossy(message); | let message_str = String::from_utf8_lossy(message); | ||||
if message_str.contains("OK") { | if message_str.contains("OK") { | ||||
1 | |||||
0xFF | |||||
} else { | } else { | ||||
0 | |||||
0x00 | |||||
} | } | ||||
} | } | ||||
#[tokio::main] | #[tokio::main] | ||||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||||
let listener = TcpListener::bind("127.0.0.1:9090").await?; | |||||
println!("Server listening on 127.0.0.1:9090"); | |||||
// 读取配置文件 | |||||
let settings = Config::builder() | |||||
.add_source(config::File::with_name("config")) | |||||
.build()?; | |||||
let address = settings.get_string("server.address")?; | |||||
let port = settings.get_int("server.port")? as u16; | |||||
let bind_address = format!("{}:{}", address, port); | |||||
let listener = TcpListener::bind(&bind_address).await?; | |||||
println!("Server listening on {}", bind_address); | |||||
loop { | loop { | ||||
let (mut socket, addr) = listener.accept().await?; | let (mut socket, addr) = listener.accept().await?; | ||||
@@ -1 +1 @@ | |||||
c40e23051f104d96 | |||||
e89aa7a333c35298 |
@@ -1 +1 @@ | |||||
{"rustc":13800692020808712694,"features":"[]","declared_features":"[]","target":8765685456636761285,"profile":8731458305071235362,"path":4942398508502643691,"deps":[[5138218615291878843,"tokio",false,17403820042732109686]],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\tcp_server-d434eb7e44cc404e\\dep-bin-tcp_server","checksum":false}}],"rustflags":[],"config":2069994364910194474,"compile_kind":0} | |||||
{"rustc":13800692020808712694,"features":"[]","declared_features":"[]","target":8765685456636761285,"profile":8731458305071235362,"path":4942398508502643691,"deps":[[5138218615291878843,"tokio",false,15265975105261538754],[18150860780478849731,"config",false,13211899394289725315]],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\tcp_server-d434eb7e44cc404e\\dep-bin-tcp_server","checksum":false}}],"rustflags":[],"config":2069994364910194474,"compile_kind":0} |