2

I have been going through this websockets article.

Can a web-socket communicate with a TCP/UDP Socket and viceversa?

Taimoor Alam
  • 113
  • 1
  • 11

2 Answers2

4

Websockets use TCP sockets. Websockets are a higher level technology relying on TCP sockets, exactly the same way HTTP is transported over TCP sockets. In fact, Websockets are a special extension of HTTP. The client issues a special HTTP request that leaves the underlying TCP socket open, which then allows both the client and the server to push data on the connection.

quentinadam
  • 3,058
  • 2
  • 27
  • 42
  • But a 'legacy' socket communicate with a Websocket? Can i open a legacy socket server in python and let a websocket communicate with it? – Taimoor Alam Feb 10 '16 at 12:57
  • A TCP socket is just a raw connection. Websockets is a higher level protocol like HTTP. It's like asking if HTTP can communicate with TCP. Of course it can, because the data in HTTP/Websocket is transported over a TCP connection, however you will need to write a client/server to handle the Websocket/HTTP protocol data. – quentinadam Feb 10 '16 at 13:28
1

What you essentially need is a WebSockets client library in your application. This will utilise TCP sockets on a lower level, and talk to your webserver using the WebSockets protocol.

The benefit of this approach is that your application code only has to deal with the library's higher-level API as well, instead of the nitty-gritty sockets API, where you'll have to implement HTTP and/or WebSockets again.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272