Note: This is not about using both node.js and HTML5 sockets. I'm also not interested in discussing the merits of the setup I'm describing.
注意:这不是关于同时使用node.js和HTML5套接字。我也不想讨论我所描述的设置的优点。
node.js runs on the server, and, since it supports connecting via sockets as a client, it can act as a middle layer between an HTML5/JS client and server that uses TCP/IP (such as a database server.) So, both node.js and WebSockets include ways of opening socket connections to a server.
node.js在服务器上运行,并且由于它支持通过套接字作为客户端进行连接,因此它可以充当HTML5 / JS客户端和使用TCP / IP的服务器(例如数据库服务器)之间的中间层。所以, node.js和WebSockets都包含打开到服务器的套接字连接的方法。
My question is, has anyone successfully ported a node.js script to WebSockets, i.e., cut node.js out of the equation, so that your web browser connects to the database directly? I imagine it would look like:
我的问题是,是否有人成功将node.js脚本移植到WebSockets,即将node.js切割出来,以便您的Web浏览器直接连接到数据库?我想它会是这样的:
- cut out everything to do with HTTP
- 切断与HTTP有关的一切
- port the usage of all node.js-specific functions to use the WebSockets API
- 移植使用所有node.js特定函数来使用WebSockets API
If this has been done, was it a lot of trouble or were the node.js and WebSockets APIs relatively similar?
如果这已经完成,是不是很麻烦,或者node.js和WebSockets API是否相对类似?
1 个解决方案
#1
4
Your question is a bit hard to parse but I'll take a stab.
你的问题有点难以解析,但我会采取刺。
If you are interested in connecting from a WebSockets client (browser) to an arbitrary TCP socket server, then you might be interesting in wsproxy which is a generic WebSockets to TCP sockets proxy. wsproxy is included with noVNC (HTML5 VNC client) and has three reference implementations in C, python and Node (node.js).
如果您有兴趣从WebSockets客户端(浏览器)连接到任意TCP套接字服务器,那么您可能会对wsproxy感兴趣,它是TCP套接字代理的通用WebSockets。 wsproxy包含在noVNC(HTML5 VNC客户端)中,并在C,python和Node(node.js)中有三个参考实现。
If you are interested in adding WebSockets support to a specific given server (i.e. the database server), then you might find this fork of libvncserver. It has support for clients that speak WebSockets (i.e. noVNC) so no proxy is needed.
如果您有兴趣将WebSockets支持添加到特定的给定服务器(即数据库服务器),那么您可能会找到libvncserver的这个分支。它支持说WebSockets(即noVNC)的客户端,因此不需要代理。
The basic wsproxy proxying functionality was pretty straight forwards to implement. The trickiest part is that the current WebSockets draft in use (v76) does not specify a binary transfer payload (only UTF-8) so wsproxy base64 encodes/decodes all traffic to/from the WebSockets client. The implementation of WebSockets connections in libvncserver was somewhat more tricky because libvncserver has some pretty hard-coded ideas about buffering/framing that needed to be worked around.
基本的wsproxy代理功能非常直接实现。最棘手的部分是当前正在使用的WebSockets草案(v76)没有指定二进制传输有效负载(仅UTF-8),因此wsproxy base64对来自WebSockets客户端的所有流量进行编码/解码。 libvncserver中WebSockets连接的实现有点棘手,因为libvncserver有一些关于需要解决的缓冲/框架的非常硬编码的想法。
Disclaimer: I'm responsible for noVNC, wsproxy and the WebSockets patches to libvncserver.
免责声明:我负责novNC,wsproxy和libvncserver的WebSockets补丁。
#1
4
Your question is a bit hard to parse but I'll take a stab.
你的问题有点难以解析,但我会采取刺。
If you are interested in connecting from a WebSockets client (browser) to an arbitrary TCP socket server, then you might be interesting in wsproxy which is a generic WebSockets to TCP sockets proxy. wsproxy is included with noVNC (HTML5 VNC client) and has three reference implementations in C, python and Node (node.js).
如果您有兴趣从WebSockets客户端(浏览器)连接到任意TCP套接字服务器,那么您可能会对wsproxy感兴趣,它是TCP套接字代理的通用WebSockets。 wsproxy包含在noVNC(HTML5 VNC客户端)中,并在C,python和Node(node.js)中有三个参考实现。
If you are interested in adding WebSockets support to a specific given server (i.e. the database server), then you might find this fork of libvncserver. It has support for clients that speak WebSockets (i.e. noVNC) so no proxy is needed.
如果您有兴趣将WebSockets支持添加到特定的给定服务器(即数据库服务器),那么您可能会找到libvncserver的这个分支。它支持说WebSockets(即noVNC)的客户端,因此不需要代理。
The basic wsproxy proxying functionality was pretty straight forwards to implement. The trickiest part is that the current WebSockets draft in use (v76) does not specify a binary transfer payload (only UTF-8) so wsproxy base64 encodes/decodes all traffic to/from the WebSockets client. The implementation of WebSockets connections in libvncserver was somewhat more tricky because libvncserver has some pretty hard-coded ideas about buffering/framing that needed to be worked around.
基本的wsproxy代理功能非常直接实现。最棘手的部分是当前正在使用的WebSockets草案(v76)没有指定二进制传输有效负载(仅UTF-8),因此wsproxy base64对来自WebSockets客户端的所有流量进行编码/解码。 libvncserver中WebSockets连接的实现有点棘手,因为libvncserver有一些关于需要解决的缓冲/框架的非常硬编码的想法。
Disclaimer: I'm responsible for noVNC, wsproxy and the WebSockets patches to libvncserver.
免责声明:我负责novNC,wsproxy和libvncserver的WebSockets补丁。