Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the fundamental difference between WebSockets and pure TCP?

Tags:

tcp

websocket

I've read about WebSockets and I wonder why browser couldn't simply open trivial TCP connection and communicate with server like any other desktop application. And why this communication is possible via websockets?

like image 671
xap4o Avatar asked Apr 21 '10 08:04

xap4o


People also ask

What is the difference between WebSocket and TCP?

WebSocket is basically an application protocol (with reference to the ISO/OSI network stack), message-oriented, which makes use of TCP as transport layer. The idea behind the WebSocket protocol consists of reusing the established TCP connection between a Client and Server.

Are WebSockets faster than TCP?

WebSockets performs quite well, with an average round trip time of about 20 microseconds (0.02 milliseconds), but straight up TCP still beats it handily, with an average round trip time of about 2 microseconds (0.002 milliseconds), an order of magnitude less.

Is WebSocket a TCP?

WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection.

What is difference between WebSocket and HTTP?

WebSocket is an event-driven protocol, which means you can actually use it for truly realtime communication. Unlike HTTP, where you have to constantly request updates, with websockets, updates are sent immediately when they are available.


1 Answers

It's easier to communicate via TCP sockets when you're working within an intranet boundary, since you likely have control over the machines on that network and can open ports suitable for making the TCP connections.

Over the internet, you're communicating with someone else's server on the other end. They are extremely unlikely to have any old socket open for connections. Usually they will have only a few standard ones such as port 80 for HTTP or 443 for HTTPS. So, to communicate with the server you are obliged to connect using one of those ports.

Given that these are standard ports for web servers that generally speak HTTP, you're therefore obliged to conform to the HTTP protocol, otherwise the server won't talk to you. The purpose of web sockets is to allow you to initiate a connection via HTTP, but then negotiate to use the web sockets protocol (assuming the server is capable of doing so) to allow a more "TCP socket"-like communication stream.

like image 114
Ash Avatar answered Oct 11 '22 09:10

Ash