Closed TomieAi closed 2 years ago
@TomieAi I turn off server for several minutes, and start again, reconnect works. Could you show me a demo code to reproduce the scenario?
BTW, currently emit
will return Error::IllegalActionBeforeOpen
if connection is down, so you should handle the result, make sure your code not exist early. #230
I turn off server for several minutes, and start again, reconnect works. Could you show me a demo code to reproduce the scenario?
weird xD its working fine right now xD yesterday it dint. 🤯 like the test yesterday is consistent.. sorry about it :(
one last thing before I close this issue..
if I expect the server to be offline after I start client.. client should try to reconnect and hoping to ignore this.
thread 'main' panicked at 'Connection failed: IncompleteResponseFromEngineIo(IncompleteResponseFromReqwest(reqwest::Error { kind: Request, url: Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("localhost")), port: Some(3000), path: "/socket.io/", query: Some("EIO=4&transport=polling&t=2169245116"), fragment: None }, source: hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 10061, kind: ConnectionRefused, message: "No connection could be made because the target machine actively refused it." })) }))', src\main.rs:26:10
is it ok by design to do this? call the main again. to ignore the error above?
use rust_socketio::{ClientBuilder, Payload, RawClient};
use serde_json::json;
use std::io;
fn main() {
let callback = |payload: Payload, socket: RawClient| {
match payload {
Payload::String(str) => println!("Received: {}", str),
Payload::Binary(bin_data) => println!("Received bytes: {:#?}", bin_data),
}
socket
.emit("test", json!({"got ack": true}))
.expect("Server unreachable")
};
// get a socket that is connected to the admin namespace
let test = ClientBuilder::new("http://localhost:3000")
.namespace("/")
.on("test", callback)
.on("error", |err, _| {
eprintln!("Error: {:#?}", err);
})
.connect();
if test.is_err() {
println!("rc");
main();
}
io::stdin().read_line(&mut String::new()).unwrap();
}
tbh im not really good at rust im a c++xD i just really wanna convert the client I made from using this https://github.com/socketio/socket.io-client-cpp but in rust.. because I find rust very interesting.
As the socketio doc said https://socket.io/docs/v3/client-socket-instance/, first time connect failed will not reconnect, must be manual reconnect, reconnect should only after previous connect is succeed.
Yes, this is definitely not the intended behavior! If the server is not available you should be notified and not try to reconnect forever!!
As the socketio doc said https://socket.io/docs/v3/client-socket-instance/, first time connect failed will not reconnect, must be manual reconnect, reconnect should only after previous connect is succeed.
Yes, this is definitely not the intended behavior! If the server is not available you should be notified and not try to reconnect forever!!
aight thank you I will do manual reconnect.
I think I'm in the wrong here and confused and I'm sorry xD haha I've never really use the real client of socket.io..
but instead I use this ..
https://www.npmjs.com/package/ngx-socket-io
https://github.com/socketio/socket.io-client-cpp
both of them will still reconnect even tho the server is not up xD because of that I assume that's the same behavior's across all client.. again sorry xD my bad.. I dint read the lifecycle on the real socket.io client
and you guys are right base on lifecycle image of socket.io client it should not do this xD I just get confused i thought its the same behavior for all clients my bad.
aight im gonna close this up.
it do nothing. when I try turn off server for 15 seconds. I tried to do
.reconnect(true)
.max_reconnect_attempts(0)
also and thereconnect_delay(3, 5)
maybe it helps. it dint.btw what I mean by "not working is" well its doing nothing no error what so ever. I know it dint reconnect because server dint log the client socket id at
connection
event. and client surely dint receive theemit test
I send to any client that successfully pass theconnection
event.if I turn off/on server quick seconds again and again.. that's fine.. the reconnection is working chief kiss <3.. but when its longer than that.. 15s+. it doesn't do anything.
I really like the socket client JS behavior's that it keeps reconnecting no matter what happen like u will get a lot of xD connection error at console. like it keeps knocking to the door or hitting the door bell until server responded back.
help me out maybe I'm missing something.
also I realize auto reconnect only covers the part where you got disconnected not when u failed to connect on 1st run.