Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can websocket messages get lost or not?

I'm currently developing a Java WebSocket Client Application and I have to make sure that every message from the server is received by the client. Is it possible that I lose some messages (once they are sent from the server) due to a connection interruption? WebSocket is based on TCP so this shouldn't happen right?

like image 787
Adrian Krebs Avatar asked Sep 09 '15 07:09

Adrian Krebs


People also ask

Are WebSocket messages guaranteed?

This message is sent once after the user connects to the WebSocket. It indicates that any message or event on a channel that arrives after the user recieves the SESSION_ESTABLISHED message is guaranteed to be delivered to the user as long as the WebSocket stays open.

Why WebSockets are not reliable?

It has built-in means of detecting transmission errors or packet corruption and attempting retransmissions in those cases, but delivery can still fail. It guarantees that if the packet is not delivered, the caller will get an error so the caller can know. Since websocket is built on top of TCP, it has the same issue.

How long does WebSocket last?

A WebSocket connection can in theory last forever. Assuming the endpoints remain up, one common reason why long-lived TCP connections eventually terminate is inactivity.


1 Answers

It can happen. TCP guarantees the order of packets, but it does not mean that all packets sent from a server reach a client even when an unrecoverable trouble happens in an underlying network. Imagine someone pulls out your LAN cable or switches off your WiFi access point at the worst timing while your application is communicating with your server. TCP does not overcome such a trouble.

To ensure that every WebSocket message sent from your server reaches your client, you have to implement some kind of SYN/ACK in the application layer.

like image 152
Takahiko Kawasaki Avatar answered Oct 03 '22 18:10

Takahiko Kawasaki