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?
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.
However, the connection between a client and your WebSocket app closes when no traffic is sent between them for 60 seconds.
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.
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.'
"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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With