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:
- Use XMLHttpRequest. I can open the connection and read the data, but I can't clear the responseText field of prior values when I get the onprogress event. I can't afford to parse the responseText for the latest value as this grows very quickly. I will also run into memory issues, so this is a no-go.
- WebSockets and Socket.IO: neither has proved successful in connecting to a telnet interface because it expects HTTP at first to then convert to direct socket.
So my question is, how do I best accomplish this? Some options I see, but I'm sure there are more:
- 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)
- 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.<
- 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.
Thanks,
Tim