0

I understand that WebSockets are built on TCP sockets and provide more user-friendly interfaces in terms of messages completion (see for instance this SO question: Differences between TCP sockets and web sockets, one more time ).

But could this alone justify choosing websockets over TCP sockets in a context where no web browser involved? Would such a design choice make sense or should WebSocket use be restricted to 'Web' environnents only?

Silverspur
  • 891
  • 1
  • 12
  • 33

2 Answers2

3

The main point of WebSockets is that they can be integrated into the typical HTTP infrastructure, i.e. they start with a HTTP handshake (or HTTPS with wss://) and are also designed to deal with HTTP proxies, look (initially) like HTTP and can use the same ports so that they can pass through firewalls ...

If these properties are needed than WebSockets are a good choice even outside of browsers. If these are not needed less complex protocols might be sufficient instead.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
2

WebSockets have an advantage over a custom TCP/IP solutions, since WebSockets experience less connectivity issues.

This is especially true for TLS + WebSockets (wss://) over port 443, and it's a benefit that isn't browser (or HTTP) specific.

This is because many firewalls, bridges and other intermediaries block different TCP/IP ports or allow limited traffic to pass through. Traffic over the HTTP and HTTPS ports (80 and 443) is often allowed even in stricter environments, which improves the chance of establishing (and retaining) a connection.

Myst
  • 18,516
  • 2
  • 45
  • 67