Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know if the message sent by websocket success or not

Tags:

I developed a chat server using websocket in cowboy, but I want to know if the message sent by server to client success.How can I know?

like image 793
ter Avatar asked Aug 17 '13 09:08

ter


People also ask

When using WebSocket send () How do you know?

The only way to know the client received the webSocket message for sure is to have the client send your own custom message back to the server to indicate you received it and for you to wait for that message on the server. That's the ONLY end-to-end test that is guaranteed.

How do I read WebSocket messages?

First, you need to copy your web browser's header to here and use json. dumps to convert it into the string format. After that, create the connection to the server by using create_connection . Then, perform the handshake by sending the message, and you will be able to see the data on your side.

Are WebSockets guaranteed delivery?

Services must handle duplicate notifications, as well as missed blocks as WebSockets do not provide guaranteed delivery.


Video Answer


1 Answers

Websocket is a rather thin abstraction layer on top of a conventional TCP socket. After the initial handshake the difference is minimal. So, the question is: how do I know if a data chunk was received by the remote peer? The short answer: only if the peer acknowledges it explicitly by the means of application-level protocol. Remote client will send TCP ACK packets for every data packet you will send it, but this fact is well hidden from the application for good reasons. Receiving ACK packet only means that remote TCP stack has dealt with it, but says nothing about how (and if) the client application has processed it.

Add a special "acknowledge receive" message type to your chat protocol. Include a monotonically increasing sequence number in all of your outgoing messages, and include the SN of the received message in the ACK message to know exactly how much data the client has already processed.

like image 111
rkhayrov Avatar answered Nov 09 '22 23:11

rkhayrov