Jeet
Jeet

Reputation: 727

How can I store/preserve the socket connections when the node server restarts

I am using webrtc.io to create the socket connections for my audio, video chat application. I want to preserve all the socket connection so that I can send updates to all the end users when the node.js server is restarted.

I am using Mongodb as the database for this application. Is there any way to store in the database and retrieve it back when the server is restarted?

Upvotes: 2

Views: 775

Answers (1)

Neil Lunn
Neil Lunn

Reputation: 151170

I'm going to give you a common life situation to explain this.

Suppose you have a mobile phone that you cannot make calls from and you can only receive calls.

Someone calls you and you can talk to them, messages pass backwards and forwards on a constant connection. This was better than SMS because you could only respond to an SMS that was sent to you as well but now you have this constant connection to talk freely on.

Now in those statements I just described what Websockets are and the difference between that an Http. Next I'll apply this to what you are asking.

Now suppose on this phone where you can only keep talking on calls you receive from someone else, your battery runs out. You find a power source to plug into and get your phone working again. So do you expect your phone to just suddenly re-establish the call that dropped when your battery ran out?

You do not initiate the connection you are talking about. So you cannot "make the call back" or "re-establish the call". This is a strictly "the customer calls you" scenario.

The best you can do is maintain the session state to the subsequent re-connection "picks up where you left off". But on a hang-up the client has to call you back.

For better availabilty you need to proxy the connection and share over multiple application server nodes, all with access to the same session state.

Upvotes: 4

Related Questions