Best way to display high speed data from telnet interface to webview?

I would like to map data coming out of the telnet interface to a webview. I have a daemon that reads CAN bus data and outputs about 500 lines ~ 40 characters per second to the telnet port. There are a few messages running at 100 Hz and most of the others are running at 10 or 5 Hz, so that's about 500 / second in total. I want to get the latest values ​​in each batch and display them on a web page. The webpage is loaded locally (not over HTTP) and the daemon can be on a different host, so there is cross-domain communication.

Here's what I've tried and failed:

  • Use XMLHttpRequest. I can open the connection and read the data, but I cannot clear the responseText field of previous values ​​when I receive the onprogress event. I cannot afford to parse the responseText for the last value as this is growing rapidly. I will also run into memory issues, so this is not-go.
  • WebSockets and Socket.IO: None of them proved to be successful when connecting to the telnet interface because it calculates HTTP first and then convert to direct socket.

So my question is, what is the best way to do this? Some options I see, but I'm sure there are more:

  • Add HTTP transform to socket in the canlogserver daemon I'm trying to connect to. How? (it's open source C so I can add to it).
  • Write a PHP interface that connects to a daemon over telnet and can feed data back to webview over HTTP. This seems grossly ineffective on multiple trips over the IP stack. <
  • Anything else in the JS client code to work around my buffer issue and read messages from the telnet server, display the data, and then flush the buffer? I need to make sure that I receive all messages after opening the socket, so opening, closing, reopening will not work as it would mean messages will be lost.

Thank,

Tim

+3


source to share


2 answers


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

However, you can use websockify to connect between a WebSocket client (browser) and a simple TCP socket. Websockify also allows you to send / receive binary data to / from a TCP server, even if the WebSocket protocol (like Hixie) or the browser doesn't support binary types directly (like typed arrays).



noVNC uses websockify to be able to directly connect to a VNC server that doesn't yet have built-in WebSocket support. Websockify even includes a small test that demonstrates connecting a simple browser-based terminal emulator to a telnetd server. Disclaimer . I did websockify and noVNC.

+2


source


The best solution is to use WebSockets if you want pure HTML5 without any plugins. Be aware of the supported browsers for such technology, you can find the list of supported browsers and the protocol version here.

WebSockets has to do a handshake when the connection is established, these are normal http lines. After that, all messages should be framed when received and when sent. The browser does this automatically, but you must implement this functionality for your daemon.

There are ready-made solutions, depending on which language you are using.



If you want to implement the WebSockets protocol yourself, check the Java implementation sources for example and use the official spec: RFC6455

I believe WebSockets is the best way to go. Java / Silverlight / Flash might be a different solution, but it takes a lot of effort and might not just be scalable like a WebSockets implementation that will handle messages and create DOM elements like DIVs in a different DIV container with received messages.

+1


source







All Articles