04-22-2016 08:40 AM
Has anyone here ever successfully used the LabVIEW WebSockets Library to create a websocket client in LabVIEW?
If so, can you share an example?
04-22-2016 08:52 AM
04-22-2016 01:31 PM
That's all very nice, but it only describes a websocket server, not a websocket client.
04-25-2016 08:23 AM
Hi Paul - I created the WebSockets library - I don't think I have any examples from applications of a WebSocket Client and I have never fully tested that functionality (I got it work well enough for my application) against the WebSocket Spec. It should be pretty straightforward though - open a TCP connection, use the SendHandshake VI and then you are free to use the read/write VIs to send/receive data from the server. I think for the client, you need to Mask the data - it's one of the inputs to the write VI, I think.
Here is a very simple example:
04-25-2016 09:06 AM
I could only get the handshake to work by modifying your "InitiateClientHandshake.vi" (see attachment). But I haven't been able to get past that. After the handshake, the 'Read' function always times out.
04-25-2016 10:12 AM
You probably also need to change the end of line constant with a \r\n as this can change depending on the target you're running the code on.
As for the read - is your websocket server actually sending out data?
My test code works fine with a LabVIEW WebSockets server, but like I said - I haven't done extensive testing on it with other websockets services.
04-25-2016 12:01 PM
I can only get "InitiateClientHandshake" to work when the line break is \n.
I'm sure the server is sending data because I can get a browser to see it.
04-25-2016 05:10 PM - edited 04-25-2016 05:10 PM
Weird - the issue with the line breaks is because a LabVIEW string has \n as termination, but on different targets, an EOL constant could be \n or \r\n or something else - HTTP specifies \r\n - it's fixed in the server handshake but didn't see it on the client side.
Is it a public server you're communicating with? Can you post your code?
04-26-2016 09:45 AM
I was mistaken about the server sending data (after the handshake, additional messaging is required before it starts sending).
After I get the server to start sending data, the Read function throws error 66. The actual data that comes out is "ˆ&êClients may not send unmasked frames". If I try masking the payload for the messages that tell the server to start sending, then I get no response.
It's not a public server, it's inside an instrument.
Attached it the test code (Note: I'm using the modified version of "InitiateClientHandshake.vi")
04-29-2016 02:37 PM
I managed to get a websocket client working with my instrument.
Attached is the modified version of the WebSockets API.