开发者

NodeJS mixing TCP sockets with websockets

I have a NodeJS TCP socket server running and I'd like to add support for websockets. Has anyone tried mixing the two in one server?

It seems like you could create the HTTP server, implement the websocket upgrade handshake, and then hand off the socket to the TCP socket server. Is that the right approach?

I considered using socket.io开发者_StackOverflow中文版, but it appears that would cut out TCP sockets.


Socket.IO supports a number of fallback technologies (e.g. JSONP long polling) which make passing the raw net.Socket back a hack that will often break.

Instead, I would suggest abstracting away the actual application logic and then connecting it via some form of adapter to both the TCP socket and Socket.IO implementations. You can then interact with each on its own API.

The APIs are somewhat similar, so this shouldn't be too difficult, but it isn't just a matter of getting some existing net.Socket object out of Socket.IO.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜