简体   繁体   English

如何在节点中的TCP上隧道WebSockets?

[英]How to tunnel websockets over TCP in node?

I am trying to tunnel websockets over TCP. 我正在尝试通过TCP隧穿websockets。 I know how to tunnel HTTPS - "Connect URL:port" is where I start. 我知道如何建立HTTPS隧道-“ Connect URL:port”是我的起点。 From there, one opens a socket to the target and then just pipe between the client and the target. 从那里,打开一个到目标的套接字,然后在客户端和目标之间建立管道。 Where do I start with websockets? 我从哪里开始使用websockets? is there something similar to a "Connect url:port" to begin with, which I can catch in my http server and then do some upgrade processing? 开始时是否有类似于“ Connect url:port”的内容,我可以在我的http服务器中捕获它,然后进行一些升级处理?

You sure you want to tunnel WebSocket over TCP? 您确定要通过TCP隧道传输WebSocket吗? WebSocket runs over TCP. WebSocket通过TCP运行。

I think you mean you want to tunnel TCP traffic with WebSocket, ie, take an existing, traditional Socket-based application and make it work over the web. 我认为您的意思是您想通过WebSocket隧道传输TCP通信,即采用现有的,传统的基于Socket的应用程序并使之在Web上运行。 If that's what you mean, you essentially put your TCP data in a WebSocket frame and on the receiving end you read the WebSocket frame and extract the data. 如果那是您的意思,则实际上是将TCP数据放入WebSocket框架中,然后在接收端读取WebSocket框架并提取数据。 Of course this is easier said than done. 当然,这说起来容易做起来难。 You have to make sure you create the WebSocket frame correctly on the sender side (also handling the TCP data stream, which also may be tricky), encrypt the data (its going over the web, right?) and on the receiving side read the WebSocket frame, extract the data from the right parts of the frame. 您必须确保在发送方正确创建WebSocket框架(还处理TCP数据流,这也可能很棘手),对数据进行加密(其通过网络传输,对吗?),并在接收方读取WebSocket框架,从框架的右侧部分提取数据。 And also you need to check to see if all the data is in one WebSocket frame or multiple frames. 另外,您还需要检查所有数据是在一个WebSocket框架中还是在多个框架中。

As I said, its not dead simple. 就像我说的那样,它并不简单。

There are several WebSocket libraries out there that may (or may) not handle all of this for you (many do not handle the multiple WebSocket frame situation). 有几个WebSocket库可能(或可能)不为您处理所有这些(很多情况下无法处理多个WebSocket框架)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM