Reputation: 169
I'm asking if it is possible to create a backend in node.js who has the same API but is compatible both TCP and WebSocket protocols, on the same port ? I'm aware that Websocket is TCP based but have some high-level pre-requisites and found nothing on the subject.
Thanks all
Upvotes: 1
Views: 86
Reputation: 163262
This might be possible depending on the protocol, but it's going to be a hassle. You'll have to hook the HTTP server (which web sockets sit on top of) and shuffle the data off to a separate handler if it appears to be invalid HTML.
This is going to be error prone. HTTP has a lot of edge cases you would need to accommodate. The alternative protocol is going to have to either be different enough to quickly identify, or actually compatible with HTTP so it can have its own protocol upgrade path.
Related: Overriding Node.js HTTP parser
Upvotes: 1