How to deal with tcp disconnection #1390
Replies: 1 comment 4 replies
-
Hi @StanLi-ops ! Welcome, and thanks for trying out the Rust guide! This is a great question. To have more control over the error handling of a function call, the Result of the call needs to be handled a little more directly, instead of using the handy The Instead of In your example, it is the A retry loop might look something like this: use ockam::{Context, Result, TcpTransport};
use std::thread::sleep;
use std::time::Duration;
#[ockam::node]
async fn main(mut ctx: Context) -> Result<()> {
let mut need_reconnect = true;
let tcp = TcpTransport::create(&ctx).await?;
while need_reconnect {
need_reconnect = tcp.connect("127.0.0.1:4000").await.is_err();
if need_reconnect {
println!("Failed to connect. Sleeping");
sleep(Duration::from_secs(1));
}
}
println!("Connected!");
ctx.stop().await
} |
Beta Was this translation helpful? Give feedback.
-
I am a novice.
I found in learning Ockam that panic occurs when the tcp connection object does not exist.
Is there a way for tcp to disconnect?
Or how should I handle the panic correctly?
I hope that when the connection object is closed or does not exist, I can try to reconnect and close it after many times.
what should I do?
This is panic
thread 'tokio-runtime-worker' panicked at 'called
Result::unwrap()on an
Errvalue: Error { code: 11009, domain: "OCKAM_NODE" }'
Beta Was this translation helpful? Give feedback.
All reactions