According to Does TCP send a SYN/ACK on every packet or only on the first connection?, the client should be able to know when a message arrives. However, send method does not seem able to take a callback. Is there a way to know when the message arrive?
-
2No, there isn't. Acknowledgements aren't visible to network applications, they're just used internally by the stack. – Barmar Dec 23 '17 at 01:28
-
If you need to know when the message arrives, design that into your application protocol so that the recipient sends a response. – Barmar Dec 23 '17 at 01:28
-
@Barmar That is very unfortunate. Thank you so much for letting me know. – SCLeo Dec 23 '17 at 01:36
-
1If you use socket.io on top of webSocket, then it has an acknowledgement/response callback feature. Internally, it just sends another message back in response as the acknowledgement which you could, of course, implement yourself with a plain webSocket. – jfriend00 Dec 23 '17 at 01:38
1 Answers
The TCP ack is internal to the TCP protocol. That is not surfaced back to the TCP client level or the webSocket level. So, these protocol-level acknowledgements are not visible to applications using TCP.
If you want positive, application-level confirmation that your message arrived, then you can have the recipient send back an application level acknowledgement message.
If you use socket.io (which runs on top of webSocket), then it has an acknowledgement/response callback feature built-in. You pass a callback to the .emit()
method which will get called when the recipient acknowledges receipt of the message. You can even have the recipient send back a specific response if desired. Internally, socket.io just sends another message back in response as the acknowledgement which you could, of course, implement yourself with a plain webSocket.

- 683,504
- 96
- 985
- 979