How to reconnect to a socket after restarting the server

advertisements

I'm building an application with realtime invalidations using a socket and while I have something working, It seems to stop working once I restart my server (heartbeat not send anymore). In the process of trying to find a cure, I realized I don't fully understand the whole concept so I decided to post several questions here:

  1. Who is in-charge of the re-connection? Is it the client?
  2. Do both sides (client and server) have to do something in order to support a re-connection mechanism?
  3. This is a bonus question - How can I achieve socket redundancy (the ability to use more than one server). Do I have to keep all connections in a session store (redis)? How do I handle re-connections in this scenario?

I try to keep this question general but in case you're interested, my application is written in Flex and uses FlashSocket.IO to connect to my server (Tornado + Tornadio2 + tornadoredis)


  • Who is in-charge of the re-connection? Is it the client?

Yes.

  • Do both sides (client and server) have to do something in order to support a re-connection mechanism?

The server has to do what it did in the first place: accept a connection. The client also has to do what it did in the first place: create a connection.

  • This is a bonus question - How can I achieve socket redundancy (the ability to use more than one server).

Connect to another server when the first one fails.

Do I have to keep all connections in a session store (redis)?

No. That would just waste connections.

How do I handle re-connections in this scenario?

The same way you handle them in any scenario. Just reconnect from the client. But if you have multiple fail-over servers you wouldn't want to reconnect to the one that just failed, you would want to create a new connection to a different member of the failover server group.