Socket.io packets get lost between disk and reconnection

I use socket.io to connect a smartphone (in a web frame) to the server and send a few messages around (a few short lines per minute, nothing big). Since smartphones often have an unstable connection, socket.io is forced to reconnect from time to time. It does this automatically, and the messages that I want to send after they notice that the connection is currently unavailable are buffered and sent as a packet after reconnecting. So basically everything is going well with socket.io.

But when I send a message right before socket.io notices that the connection is gone, the message is lost. It cannot be transmitted, but it does not receive socket.io buffering. I am quite happy with the .io socket, but this problem causes me since I do not send many messages, but I really need the ones that I send for sending, reliably. While the connection is established, all messages are transmitted perfectly, so I do not need to check this. Only the second between the loss of connection and socket.io notices that this is a critical moment when I encounter packet loss.

I was thinking about how to simulate the behavior of TCP with serial numbers and ACK, but it is a bit like shooting ants with a rocket launcher. So my question is: does anyone have an easy solution to this problem, or even comes across this myself? I donโ€™t even ask for explicit code - I can do it myself, but a concept or something like that to get rid of this particular problem would be great.

Thanks in advance!

+7
javascript
source share
2 answers

Why don't you just log every message in the database? And use the socket.io confirmation function to make it even better.

from http://socket.io/#how-to-use SERVER

var io = require('socket.io').listen(80); io.sockets.on('connection', function (socket) { socket.on('ferret', function (name, fn) { fn('woot'); }); }); 

CLIENT

 <script> var socket = io.connect(); // TIP: .connect with no args does auto-discovery socket.on('connect', function () { // TIP: you can avoid listening on `connect` and listen on events directly too! socket.emit('ferret', 'tobi', function (data) { console.log(data); // data will be 'woot' }); }); </script> 
+2
source share

If this is so important, I will probably imitate the naive version of TCP. Just save the buffered client side and reply the server to confirm this message, otherwise send again from the buffer.

0
source share

All Articles