是否有用于 JavaScript 的 Telnet 库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4725625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 13:47:29  来源:igfitidea点击:

Is there a Telnet library for JavaScript?

javascripttelnet

提问by Pat O

We have a network camera. It has an HTTP server to provides the current image. There is also a Telnet interface for controlling the camera (i.e. trigger, focus, etc.). I would like to add an HTML page to the camera that would provide a simple interface (we already have client software we write). I can "GET" the image and display that, but I would also like to have controls that use the Telnet interface to control the camera. So a button might have JavaScript code behind it that connects to the camera via Telnet (logs in) and issues the command to trigger the camera.

我们有网络摄像机。它有一个 HTTP 服务器来提供当前图像。还有一个Telnet接口用于控制相机(即触发、对焦等)。我想向相机添加一个 HTML 页面,该页面将提供一个简单的界面(我们已经编写了客户端软件)。我可以“获取”图像并显示它,但我也希望使用 Telnet 界面来控制相机。因此,一个按钮背后可能有 JavaScript 代码,它通过 Telnet(登录)连接到摄像头并发出触发摄像头的命令。

I know that JavaScript/browsers support connecting to the same host via XMLHttpRequest. In this case I would be looking to open a socket on port 23 and send text. I also know that I can do this through Flash, Java, or some other technology, but I would prefer to use JavaScript only. If that is possible.

我知道 JavaScript/浏览器支持通过XMLHttpRequest连接到同一主机。在这种情况下,我希望在端口 23 上打开一个套接字并发送文本。我也知道我可以通过 Flash、Java 或其他一些技术来做到这一点,但我更愿意只使用 JavaScript。如果可以的话。

采纳答案by Adam Davis

Thomaschaaf is correct, while HTML5 introduces websockets you'll find they still require special server support as they post HTTP style information upon opening the socket:

Thomaschaaf 是正确的,虽然 HTML5 引入了 websockets,你会发现它们仍然需要特殊的服务器支持,因为它们在打开套接字时发布 HTTP 样式信息:

JS/HTML5 WebSocket: Connect without HTTP call

JS/HTML5 WebSocket:无需 HTTP 调用即可连接

The best way, currently, to have true sockets is to either

目前,拥有真正套接字的最佳方法是

  • use a flash or Java component on the webpage that does the actual socket work.
  • use a proxy server with websockets that can handle the additional protocol overhead of websockets and connect to the real tcp/ip port with plain sockets.
  • 在执行实际套接字工作的网页上使用 Flash 或 Java 组件。
  • 使用带有 websockets 的代理服务器,它可以处理 websockets 的额外协议开销,并使用普通套接字连接到真实的 tcp/ip 端口。

The jsterm example Matt linked does the latter, and if your webcans are behind a firewall it will not work in your situation without also implementing another server.

jsterm 示例 Matt links 执行后者,如果您的 webcans 位于防火墙后面,它在您的情况下将无法正常工作,而无需实现另一台服务器。

There are libraries that implement the first method, two are linked here for convenience, many others can be found using a search engine:

有一些库实现了第一种方法,为了方便起见,这里链接了两个,使用搜索引擎可以找到许多其他方法:

http://stephengware.com/proj/javasocketbridge/(Java)

http://stephenware.com/proj/javasocketbridge/(Java)

http://matthaynes.net/blog/2008/07/17/socketbridge-flash-javascript-socket-bridge/(Flash)

http://matthaynes.net/blog/2008/07/17/socketbridge-flash-javascript-socket-bridge/(Flash)

回答by Matthew Cook

jsTermis an HTML5 implementation of a Telnet client.

jsTerm是 Telnet 客户端的 HTML5 实现。

You'll need a browser that supports HTML5 WebSockets. WebSocketsis the only method of doing non-HTTP requests with pure JavaScript.

您需要一个支持 HTML5 WebSockets 的浏览器WebSockets是使用纯 JavaScript 执行非 HTTP 请求的唯一方法。

回答by Thomaschaaf

Currently there is no way to do socket connections with JavaScript only.

目前无法仅使用 JavaScript 进行套接字连接。

But what you are searching for is a socket connection ;)

但是您要搜索的是套接字连接;)

https://developer.mozilla.org/en/XML_Extras

https://developer.mozilla.org/en/XML_Extras

回答by Per Lundberg

If I interpret the question liberally as "is there a remote connectivity library for Javascript", then the answer is yes (quoting from https://xtermjs.org/):

如果我将这个问题解释为“是否有用于 Javascript 的远程连接库”,那么答案是肯定的(引自https://xtermjs.org/):

I've tried WebSSH2 with node.js briefly, it worked for me - I managed to connect to a Linux-based server with it.

我已经简单地尝试过使用 node.js 的 WebSSH2,它对我有用 - 我设法用它连接到基于 Linux 的服务器。

(I know this probably doesn't help the OP but this is a 7-year old question anyway. Maybe it helps others who are needing an answer to a similar problem.)

(我知道这可能对 OP 没有帮助,但无论如何这是一个 7 年前的问题。也许它可以帮助其他需要回答类似问题的人。)