streaming data using the LwIP server - javascript

I have an embedded system which is running the LwIP server(v1.2), I need to be able to stream a data array into the javascript on the client side? I'm looking at using chrome and some HTML5 features, so some people have suggested using websockets. Does anyone know where I need to start to use these with the LwIP framework? Any help at all would be much appreciated!

WebSockets is a relatively simple protocol so you could use the protocol spec and write your own server. Since lwIP offers a bsd sockets API, you could also search for existing open source C servers. (A quick search shows up this candidate for instance. BTW, note that this code licensed as GPL. You should only use it if you understand the requirements using GPL'd code puts on your project.)
Note that while Chrome support for websockets is good, support is patchier if you later decide to use other browsers (and particularly to allow users with older browsers). See here for details. If support for a variety of browsers matters to you, you'll probably have to include code in client and server to fallback to long polling when a websocket handshake fails.

Related

HTML5 WebSockets, was the standard changed?

I'm working with NodeJS and found this code that implements kind of native support for sockets since NodeJS doesn't supports sockets by default.
So I used the code to open a server(server is waiting...), now for the client side I used some simple html file on my desktop with code like that, well at first glance it fail, but when I debug the code a bit I found out the the NodeJS socket code I found needs sec-websocket-key1 and sec-websocket-key2 while I get from the client-side code I implemented(in the plnkr) only sec-websocket-key.
I looked that up and found that link that saying:
The first protocol used by HTML5 WebSockets was
draft-ietf-hybi-thewebsocketprotocol-00 (HyBi 00). All was well until
the protocol was upgraded to remedy some security issues. As a result
of these changes, the Sec-WebSocket-Key1 and Sec-WebSocket-Key2 fields
were added to the client header.
Basically that explains why I get sec-websocket-key, I know that article also say that(according to caniuse) there only 2 browser supports the latest websockets protocol, I tested with chrome and firefox and both sends the same sec-websocket-key...
What is the true protocol I should support(is the right one), the one used web-socket-key1/2 or just sec-websocket-key
Which browsers supports(if those should be supported) sec-websocket-key1 and sec-websocket-key2?
Am I doing something entirely wrong with my client-side Web Sockets or the server side?
Is there a shim to fix something?
The article is several years old and describes version 6 of the protocol, which was still only a draft is now long obsolete. The current version is 13 and is described in RFC 6455. And this is the version you will find implemented in all current browsers.
Thus it is best to simply ignore the article or only see it in a historical context. For any new implementation please refer to the RFC only and not to any previous drafts.
I know that article also say that(according to caniuse) there only 2 browser supports the latest websockets protocol,
Looking at caniuse shows that all current browsers support the relevant version of Websockets.
since NodeJS doesn't supports sockets by default.
This question from 2013 has an overview of several implementations. I'm pretty sure that widely used implementations like Socket.IO support the latest version of the protocol.

TCP/IP socket communication in HTML5

I'd like to know if my idea is even possible, but based on everything I've searched for so far, it seems like it's not possible. I would love to hear what the experts think.
Goal: Interface with laboratory equipment via TCP/IP sockets using HTML/Javascript.
One problem is that I have no control to program the server. Therefore, I can't use HTML5 websockets. The vendor has not implemented websockets. The equipment server waits for a socket connection, and then communicates via API.
Because HTML5 and Javascript are relatively OS-independent and are 'built' for user display, I'd like to create a browser-based program. I've found related questions and answers on SO, but they are older now, so I'm wondering what is the current technology.
Thanks in advance, and please let me know if you have any questions.
The W3C published a first draft for a 'Raw Socket' standard:
http://www.w3.org/TR/raw-sockets/
I think this might be what you're looking for, but I wouldn't count on it being implemented by vendors in the near future, since it's only a first draft.
Another thing I found out while searching, is that chrome apparently enables tcp/ip communications in extensions (did not check this myself, so can't gurantee):
http://developer.chrome.com/apps/app_network.html
If possible, you might consider writing a chrome extension (though it's not really "HTML5").
I read this as needing essentially a telnet session to your equipment.
Currently, there's no way to do this from the browser without a plugin.
This question has some similar discussion: Best way to display high-speed data from a telnet interface on a web view?
Why not use the server where the HTML5/Javascript code is created. To create to connection to the device and convert this to something you can use, like websockets.

Implement WebSockets in Android using Native Sockets

There is a javascript code residing in my Android app's webkit container. This code makes use of WebSockets to communicate with the server. The same JS code works in other platforms such as iOS, but in Android 2.3, it doesn't. I read somewhere that the webkit in Android does not support WebSockets, and support will come only in Jelly Bean onwards.
In view of this, I need to provide a wrapper from the native layer (in Java) making use of plain sockets. From the little I know about sockets, it seems straightforward to support the usual APIs such as open(), send(), receive(), etc.
Is there anything else I need to know that the WebSocket protocol needs, which I will need to provide from the wrapper code? After all, the server talks to the client (my android app) as if it is a WebSocket, and not a native socket.
Some notes to consider: a) I cannot make use of any third-party library - it will have to be developed in-house. b) There will not be any binary data transferred; only text.
Thanks,
Rajath
Websockets are not raw sockets, they require an initial handshake then simple per-message framing. See the protocol spec for details. The sections on handshake and data framing will be most relevant.
I know you said you can't use third party libraries but be aware that projects like Java-Websocket might be interesting to you. It's liberally licensed so suitable for inclusion in any closed source app. Or you might find it useful as a reference while debugging your own code.

Do you use any client-side javascript library or jQuery plugin for WebSockets?

I need to deal with breaking connections and other standard things which are not handled by WebSockets yet. Something tells me that there must be plenty of plugins to do this. Do you use anything like that or write your own routines?
I need it for the client side, since I use Sinatra on the server side.
There are two common issues at hand: supporting older browsers that don't natively support WebSockets and automatic reconnect (in case of breaking connections).
Older browsers are supported by several vendors and products through emulation using different transports - what you need to look at is how good the emulation is. Here's a brief article on the topic describing the problem and Kaazing's solution [disclaimer: I work for Kaazing].
The Kaazing WebSocket Gateway also provides automatic reconnect - in case the connection breaks.
You can download the free developer version of the Kaazing Gateway - to give it a try.

Serial communication from JavaScript?

Is it possible to communicate over a machine's serial port through JavaScript?
I have to write a short program that sends data to a microcontroller over the serial port that has a GUI and is cross-platform compatible, and I really don't want to use Java's Swing.
JavaScript itself doesn't have any built in functionality to allow you to access the serial port. However, various JavaScript engines (v8, rhino, etc) allow you to write your own custom native objects.
You might want to check out node.js, which is a JavaScript library for v8 that's focused on writing server-side code (rather than web browser client code). It seems that someone's already written a serialport package for that:
https://github.com/voodootikigod/node-serialport
This is an old question, but in case this helps anyone else, Chrome Apps have access to a serial API - http://developer.chrome.com/apps/serial.html - which might help.
It's Chrome specific (obviously..), but Chrome is available cross-platform so might answer the question.
There's a cross platform plugin for serial port communication called jUART.
Yes, it's possible using an ActiveX(I did it). You can make an activeX and use JavaScript to invoke it.
If you prefer, you can make a .net dll and register it using regasm. Take a look at this link
You also can write an activeX using VB6 and register it. Both works fine.
Ps.: if you are using ActiveX, the JavaScript code will run just on IE.
If you have a DLL library (this includes e.g. most Windows APIs) that allows you to communicate over serial port you can invoke it from Firefox chrome code (or content code with universalxpconnect privileges) by using ctypes.
What you could do is to use a Java applet that connects to the local computer's Java application that reads the serial port. The applet would then transfer the data to a JavaScript class or something that can hold the information. Then additional JavaScript code can be used to access the data. It's a complicated solution but should work.
Another way is to create a POJO service.

Categories

Resources