socket.io-client-java icon indicating copy to clipboard operation
socket.io-client-java copied to clipboard

When does the socket stop to try to emit a message when connection is lost?

Open AljoSt opened this issue 9 years ago • 8 comments

Hi, I couldn't find an answer to this in the docs. So when I switch off internet on my phone, emit a message and then turn internet back on (after a couple of seconds), the message is sent to the server. If I switch it off and wait longer before turining it back on, the message is not emitted. So does some event (Socket.EVENT_CONNECTION_ERROR, Socket_EVENT_DISCONNECT, ...) mean that retrying to emit the message is stopped?

AljoSt avatar Jun 29 '16 01:06 AljoSt

I think SocketIO not implemented re emit function because I have found the same problem,an than I implemented a message buffer to handle re emit when SocketIO reconnect by self.

PatrickSR avatar Jun 29 '16 02:06 PatrickSR

As I said, the socket apparently does reemit. When I call socket.emit while there is no connection to the internet and then turn the wifi on after some seconds, the message is sent to the server

AljoSt avatar Jun 29 '16 05:06 AljoSt

I think appear re-emit only in a few seconds when socketio reconnect,if no connection too long(more than one minute),will not happen. I have tried it so I manually handle it ensure message can be re-emit.

PatrickSR avatar Jun 29 '16 05:06 PatrickSR

Yeah, the question is, how can I kow that the re-emit won't be executed anymore, so that I can shedule it manually again? "More than one minute" is not exact enough ;) (or is it??) I would think that re-emitting stops when the first EVENT_CONNECTION_ERROR or EVENT_DISSCONNECT occurs, but I can't find sth that assures that. Another solution would be to cancel an emit, but I also don't know if that's possible..

AljoSt avatar Jun 29 '16 06:06 AljoSt

You right, these all my guess so expression is not exact enough. Currently there is no API to control re-emit.I just consider how to avoid triggers socketio re-emit.

PatrickSR avatar Jun 29 '16 07:06 PatrickSR

From what I see here: https://github.com/socketio/socket.io-client-java/blob/master/src/main/java/io/socket/client/Socket.java#L391 apparently it always tries to reemit? I tried again and even after 4 minutes of connection loss, it reemits. Apparently I made a mistake before.

AljoSt avatar Jul 01 '16 04:07 AljoSt

hey mate, even though this issue is already older I am facing the exact problem in javascript instead of Java. It sometimes reemits the messages as soon as the connection is back online and it sometimes doesn't, or just a part of all the emits during that time. Did you figure something out in the mean time? Or did you stop working with socket io?

ghost avatar Mar 04 '19 16:03 ghost

Sorry, I discontinued the project before I managed to find a fix. What you could do, is to handle the (re-)sending process yourself. And in order not to process duplicate messages on the server (in case socketIO does resend a message after an interrupted connection), you could include a timestamp and an expiry date in the message. Don't know if that helps. good luck :)

AljoSt avatar Mar 04 '19 16:03 AljoSt