LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Websocket Client

Has anyone here ever successfully used the LabVIEW WebSockets Library to create a websocket client in LabVIEW?

If so, can you share an example?

 

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 1 of 21
(7,010 Views)
Look here:

http://www.notatamelion.com/2015/12/07/if-the-socket-fits-wear-it/

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 21
(7,004 Views)

That's all very nice, but it only describes a websocket server, not a websocket client.

 

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 3 of 21
(6,980 Views)

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:

WebSocketClient2016.png


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 4 of 21
(6,946 Views)

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.

 

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 5 of 21
(6,940 Views)

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.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 6 of 21
(6,932 Views)

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.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 7 of 21
(6,914 Views)

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?


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 8 of 21
(6,892 Views)

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")

 

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 9 of 21
(6,868 Views)

I managed to get a websocket client working with my instrument.

Attached is the modified version of the WebSockets API.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 10 of 21
(6,815 Views)