Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is websocket connection reliable?

Tags:

java

websocket

I always thought that web socket guarantees delivery of data as it is built on top of TCP which is reliable. I was reading the Java web socket API documentation on this link https://docs.oracle.com/javaee/7/api/javax/websocket/RemoteEndpoint.html
It says that

There is no guarantee of the successful delivery of a web socket message to the peer, but if the action of sending a message causes an error known to the container, the API throws it.

Shouldn't TCP gurantee the message delivery?

like image 202
Tejas Avatar asked Mar 17 '16 08:03

Tejas


People also ask

Can WebSockets be hacked?

Some WebSockets security vulnerabilities arise when an attacker makes a cross-domain WebSocket connection from a web site that the attacker controls. This is known as a cross-site WebSocket hijacking attack, and it involves exploiting a cross-site request forgery (CSRF) vulnerability on a WebSocket handshake.

How long do WebSocket connections last?

However, the connection between a client and your WebSocket app closes when no traffic is sent between them for 60 seconds.

Are WebSockets better than rest?

Whether you chose REST or WebSocket, one thing is certain your application will be able to communicate properly with other apps/software. You need to pick one based on your communication requirements and expectations. REST is far advanced and secured while WebSocket depends on lower-level components.


2 Answers

Reliable != Guaranteed. Reliable means you'll be notified if there was a failure (or success) - if the end users unplugs their lan cable, even tcp can't 'guarantee delivery.'

like image 128
ABuckau Avatar answered Oct 19 '22 16:10

ABuckau


"Guarantee" is a bit misleading. TCP will make a best attempt to send ordered data sent by one TCP stack to be received in-order by another TCP stack. If this cannot be done, the TCP stacks will engage in an error situation. This is no different than a money-back guarantee you get from a store; failure mode means you get a replacement and try again... eventually if too many failures and get your money back (e.g., connection broken).

Also... a TCP "guarantee" does not mean the data is "guaranteed" to be handled correctly at the application levels of both stacks. This is the responsibility of application protocols. After its work is done, TCP hands it off to the application layers above it which implement things like pub/sub, http, rpc, tuple spaces, email, ftp, transactions, databases, etc, etc...

like image 43
FrankG Avatar answered Oct 19 '22 17:10

FrankG