在 Web 视图上显示来自 telnet 接口的高速数据的最佳方式? [英] Best way to display high-speed data from a telnet interface on a web view?

查看:38
本文介绍了在 Web 视图上显示来自 telnet 接口的高速数据的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Web 视图上显示来自 telnet 界面的数据.我有一个守护进程正在运行,它读取 CAN 总线数据并在 telnet 端口上每秒生成大约 500 行 ~40 个字符.这是一些以 100 Hz 运行的消息,而大多数其他消息以 10 或 5 Hz 运行,因此总而言之,它大约是 500/秒.我想获取每个数据包中的最新值并将其显示在网页上.网页在本地加载(不是通过 HTTP),守护进程可能在不同的主机上,因此存在跨域通信.

I'd like to display data coming off a telnet interface on a web view. I have a daemon running which reads CAN bus data and produces about 500 lines of ~40 characters per second onto a telnet port. It's a few messages running at 100 Hz and most others running at 10 or 5 Hz, so in sum it's about 500 / second. I want to grab the latest values in each packet and display those on a web page. The web page is loaded locally (not via HTTP) and the daemon might be on a different host, so there is cross-domain communication.

以下是我尝试过但未能做到的:

Here's what I tried and failed to do:

  1. 使用 XMLHttpRequest.我可以打开连接并读取数据,但是当我收到 onprogress 事件时,我无法清除先前值的 responseText 字段.我无法解析 responseText 以获得最新值,因为它增长得非常快.我也会遇到内存问题,所以这是不行的.
  2. WebSockets 和 Socket.IO:都没有证明可以成功连接到 telnet 接口,因为它首先期望 HTTP 然后转换为直接套接字.

所以我的问题是,我怎样才能最好地做到这一点?我看到了一些选项,但我确定还有更多选项:

So my question is, how do I best accomplish this? Some options I see, but I'm sure there are more:

  1. 在我尝试附加到的 canlogserver 守护进程中添加 HTTP 到套接字转换.如何?(它是开源的 C,所以我可以添加)
  2. 编写一个 PHP 接口,该接口通过 telnet 连接到守护程序,并可以通过 HTTP 将数据泵回 Web 视图.通过 IP 堆栈进行多次旅行,这似乎非常低效.<
  3. JS 客户端代码中是否还有其他内容可以绕过我的缓冲区问题并从 telnet 服务器读取消息、显示数据然后转储缓冲区?我需要确保在打开套接字后获得所有消息,因此打开、关闭、重新打开将不起作用,因为这意味着消息丢失.
  1. Add HTTP to socket conversion in the canlogserver daemon I'm trying to attach to. How? (it's open source C so I could add to it)
  2. Write a PHP interface which attaches to the daemon via telnet and can pump data back to web view via HTTP. This seems grossly inefficient with multiple trips through the IP stack.<
  3. Anything else on the JS client code to circumvent my buffer issue and read messages from telnet server, display data and then dump the buffer? I need to make sure I get all the messages once the socket is opened, so opening, closing, reopening won't work since that will mean messages are lost.

谢谢,

蒂姆

推荐答案

实际上,WebSockets 有一个类似于 HTTP 的握手,然后为每条消息提供一些框架(它们不是握手后的原始套接字).

Actually, WebSockets have an HTTP-like handshake and then have some framing for each message (they are not raw sockets after the handshake).

但是,您可以使用 websockify 在 WebSocket 客户端(浏览器)和普通 TCP 套接字之间进行桥接.即使 WebSocket 协议(例如 Hixie)或浏览器不直接支持二进制类型(例如 Typed Arrays),Websockify 还使您能够向/从 TCP 服务器发送/接收二进制数据.

However, you could use websockify to bridge between a WebSocket client (browser) and a plain TCP socket. Websockify also enables you to send/receive binary data to/from the TCP server even when the WebSocket protocol (e.g. Hixie) or the browser doesn't support binary types directly (e.g. Typed Arrays).

noVNC 使用 websockify 能够直接连接到尚未内置 WebSocket 的 VNC 服务器支持.Websockify 甚至包含一个小测试,演示将一个简单的基于浏览器的终端模拟器连接到 telnetd 服务器.免责声明:我制作了 websockify 和 noVNC.

noVNC uses websockify to be able to connect directly to a VNC server that does not yet have builtin WebSocket support. Websockify even has a small test included that demonstrates connect a simple browser-based terminal emulator to a telnetd server. Disclaimer: I made websockify and noVNC.

这篇关于在 Web 视图上显示来自 telnet 接口的高速数据的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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