Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ServerSockets and Websockets?

Tags:

dart

There appears to be 2 ways to maintain an open connection between a Dart server and a Dart client: ServerSocket and Websocket.

https://www.dartlang.org/dart-by-example/#sockets
https://www.dartlang.org/dart-by-example/#websockets

When is it best to use one instead of the other?

like image 658
OCDev Avatar asked Jul 20 '14 13:07

OCDev


People also ask

What is the difference between sockets and WebSockets?

Both WebSocket vs Socket.io are popular choices in the market; let us discuss some of the major Difference Between WebSocket vs Socket.io: It provides the Connection over TCP, while Socket.io is a library to abstract the WebSocket connections. WebSocket doesn't have fallback options, while Socket.io supports fallback.

What is better than WebSockets?

SSE is best used when it's not necessary to send data from client to server. For example, in status updates and push notification applications, the data flow is from the server to the client only. This is what SSE is designed for, so WebSocket would be overkill.

What is a difference between long polling and WebSockets?

WebSockets are Full-Duplex meaning both the client and the server can send and receive messages across the channel. Long Polling is Half-Duplex meaning that a new request-response cycle is required each time the client wants to communicate something to the server.

Should I use WebSockets or REST API?

WebSocket is ideal for a scenario where high loads are a part of the game, i.e. real-time scalable chat application, whereas REST is better fitted for occasional communication in a typical GET request scenario to call RESTful APIs.


1 Answers

Websocket is a protocol build on top normal sockets that are based on the TCP protocol (ServerSocket and Socket). Websockets give you more comfort during programing, because it helps you with:

  • Framing: TCP is stream based, Websockets allow you to send packages. You don't have to find the start and end of your package on your own.
  • Closing Handshake: You can send a connection close reason.
  • Security (in browser context, not required in console application context)
  • You can also access your Websocket server via a Webbrowser API.

If you want to work together with existing Servers / Clients that are using TCP, that you have to use ServerSockets. Websockets and ServerSockets are not compatible (intentionally, for security reasons). As Websockets have more internal stuff to do the performance and throughput will not be as good as raw TCP, but this point is negligible.

Both protocols can be used with encryption, Websockets by using a HTTPS connection (wss://) and TCP using TLS (SecureSocket and SecureServerSocket).

For more details about Websockets, take a look at the RFC. RawDatagramSocket allows you to use the UDP protocol in addition to the TCP based ServerSockets.

like image 188
Fox32 Avatar answered Oct 29 '22 16:10

Fox32