tokyo_kabutomushi
tokyo_kabutomushi

Reputation: 65

I want to detect disconnect event as soon as app user close the socket

I am developing a application of two-way communication in SocketIO between App of iPhone and server.

Once app user disconnect the socket connection from the application, it was found that it takes about 30 seconds to detect the disconnect event on the server side.

I am in trouble is to not be detected immediately disconnect event on the server side.

To borrow your wisdom.

io.sockets.on('connection', function (socket) { socket.on('disconnect', function () { //disconnection process... }); });

    (Server-side)     · NodeJS (v0.10.26)           - [email protected]

    (Client side)     · Swift1.6          - SIOSocket     · Xcode6.4

Upvotes: 0

Views: 4286

Answers (2)

Mojtaba Hosseini
Mojtaba Hosseini

Reputation: 119877

You should handle these:

  1. If you disconnect on the client side, you get it immediately
  2. If the server wants to disconnect, it should send a close event to the client so that you can detect the disconnection immediately.
  3. You should monitor the network connection (using Network framework for example) and detect network loss. It is very close to immediate.
  4. You should ping the server from time to time and consider disconnecting if the server doesn't respond. It depends on the ping rate but consider that it increases your data usage and server load if you pick a very short time for ping.

Upvotes: 0

ralh
ralh

Reputation: 2564

Unless you explicitly close the socket on the client side with socket.disconnect(), there is no way to instantly detect disconnection. It was further explained here:

https://stackoverflow.com/a/32009603/5169236

So if your app simply loses internet access, gets closed and wiped from memory etc., and you don't explicitly close the socket, there is no way to detect it instantly.

Upvotes: 1

Related Questions