billroy / socket.io-arduino-client

A socket.io client for the Arduino Ethernet shield
MIT License
195 stars 66 forks source link

I can't reconnect to my server after my server crushed. #3

Open wensonsmith opened 10 years ago

wensonsmith commented 10 years ago

I have saw the code in monitor function.

if (!client.connected()) {

            // I print the connect result here
    Serial.print(client.connect(hostname,port));

    if (!client.connect(hostname, port)) return;
}

When my server crushed, it start to connect again. After i restart my server, it always return 0. It can't reconnected to server.

Then delete the monitor ,and test by this codes

if(!client.connected()){
    Serial.print("Reconnecting```");
    if(client.connect(hostname,port))
      Serial.print("Connected");

      Serial.print("\n");
  }else{
    Serial.print("Available \n");
  }
  delay(1000);

I still can't reconnect to my server.

Please help me ! Thanks a lot .

My server code:

var io  = require('socket.io').listen(8686);
io.sockets.on("connection",function(socket){
    socket.send("Socket Connected...");

    socket.on("message",function(message,callback){
        socket.broadcast.emit(message);
        console.log(message);
    });

});
billroy commented 10 years ago

It could be many things. What do the server logs say when the Arduino is trying to reconnect?

Follow the logs, they are your best help in opaque situations like this.

-br

On Nov 5, 2013, at 9:24 AM, Wenson Smith notifications@github.com wrote:

I have saw the code in monitor function.

if (!client.connected()) {

        // I print the connect result here
Serial.print(client.connect(hostname,port));

if (!client.connect(hostname, port)) return;

} When my server crushed, it start to connect again. After i restart my server, it always return 0. It can't reconnected to server.

Then delete the monitor ,and test by this codes

if(!client.connected()){ Serial.print("Reconnecting```"); if(client.connect(hostname,port)) Serial.print("Connected");

  Serial.print("\n");

}else{ Serial.print("Available \n"); } delay(1000); I still can't reconnect to my server.

Please help me ! Thanks a lot .

My server code:

var io = require('socket.io').listen(8686); io.sockets.on("connection",function(socket){ socket.send("Socket Connected...");

socket.on("message",function(message,callback){
    socket.broadcast.emit(message);
    console.log(message);
});

}); — Reply to this email directly or view it on GitHub.

fbritop commented 10 years ago

Hi Bill, Thanks for your lib, it works very well when the ethernet shield is connected directly to internet. But my actual project, my Ether shield, connects to a small modem/router which has an USB input for a broadboand mobile GSM modem. If I unplug the usb modem, the router connection to internet is lost, but client.connected still returns true, because it still connected to the router internal LAN, so the library, still think he is connected. Is there a way to test the connection directly from the library, in order to see if it is really connected to the server. I did a walkthroug establishing a connection to a web page, which indicates my gateway, so if there was a change on the gateway IP, a reconnection was forced, by the disconnect method. Is there a cleaner way using your lib?

Thanks in advance

billroy commented 10 years ago

Thanks for your note. It’s an interesting problem.

The only thing that comes to mind is to wonder whether a periodic message exchange through the socket.io connection might confirm whether or not the full TCP path is connected. On an error you could reconnect.

If your application will support the extra traffic, it might be worthwhile to try.

-br

On May 20, 2014, at 5:34 PM, fbritop notifications@github.com wrote:

Hi Bill, Thanks for your lib, it works very well when the ethernet shield is connected directly to internet. But my actual project, my Ether shield, connects to a small modem/router which has an USB input for a broadboand mobile GSM modem. If I unplug the usb modem, the router connection to internet is lost, but client.connected still returns true, because it still connected to the router internal LAN, so the library, still think he is connected. Is there a way to test the connection directly from the library, in order to see if it is really connected to the server. I did a walkthroug establishing a connection to a web page, which indicates my gateway, so if there was a change on the gateway IP, a reconnection was forced, by the disconnect method. Is there a cleaner way using your lib?

Thanks in advance

— Reply to this email directly or view it on GitHub.