将node.js服务器端代码移植到HTML5 WebSockets [英] Porting node.js server-side code to HTML5 WebSockets

查看:71
本文介绍了将node.js服务器端代码移植到HTML5 WebSockets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这不是关于同时使用node.js和HTML5套接字。我也没有兴趣讨论我正在描述的设置的优点。

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 / JS客户端和使用TCP / IP的服务器(例如数据库服务器)之间的中间层。因此,node.js和WebSockets都包含开放方式与服务器的套接字连接。

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脚本移植到WebSockets,即将node.js切割出等式,以便您的Web浏览器直接连接到数据库?我想它会是这样的:

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:


  1. 删除与HTTP有关的一切

  2. port使用情况所有node.js特定函数使用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?

推荐答案

你的问题有点难以解析但是我会采取刺。

Your question is a bit hard to parse but I'll take a stab.

如果您有兴趣从WebSockets客户端(浏览器)连接到任意TCP套接字服务器,那么您可能会对 wsproxy ,它是TCP套接字代理的通用WebSockets。 wsproxy包含在 noVNC (HTML5 VNC客户端)中,并在C,python和Node(节点)中有三个参考实现.js)。

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支持添加到特定的给定服务器(即数据库服务器),那么您可能会发现这个libvncserver的分支。它支持说WebSockets的客户端(即noVNC),因此不需要代理。

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.

基本的wsproxy代理功能非常直接实现。最棘手的部分是当前正在使用的WebSockets草案(v76)没有指定二进制传输有效负载(仅UTF-8),因此wsproxy base64对来自WebSockets客户端的所有流量进行编码/解码。 libvncserver中WebSockets连接的实现有点棘手,因为libvncserver有一些非常硬编码的关于缓冲/框架的想法需要解决。

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.

免责声明:我' m负责noVNC,wsproxy和libvncserver的WebSockets补丁。

Disclaimer: I'm responsible for noVNC, wsproxy and the WebSockets patches to libvncserver.

这篇关于将node.js服务器端代码移植到HTML5 WebSockets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆