The LabVIEW WebSockets API library allows a web browser to communicate with a LabVIEW™ application acting as a WebSocket server. Web Sockets offers low-latency communications between a LabVIEW™ application and a web browser with no plug-ins or LabVIEW™ run-time engine installation requirements.
It contains VIs for performing WebSockets handshaking, reading/writing data and closing the connection. The API allows code to be written for your LabVIEW™ application to act as both a Web Sockets server (e.g. communicate with a browser), and as a client (e.g. to talk to existing WebSockets services).
As it uses the native TCP/IP VIs in LabVIEW™, it works on both desktop LabVIEW™ (e.g. Windows, Linux etc.) and also LabVIEW™ RT (e.g. CompactRIO, sbRIO etc.).
MediaMongrels Ltd has extensive experience of using this library to create dynamic web-based user interfaces for LabVIEW™ applications. If you would like to use our services to incorporate the library into your application, please contact us to discuss your requirements.
Links / Examples
- WebSockets API on GitHub
- WebSockets API on NI Tools Network
- WebSockets – Bringing LabVIEW to the Web (Presentation)
- myRIO Giant Tetris (NI Community)
- Boat Monitoring System (Presentation)
WebSockets API on the LabVIEW™ Tools Network
- Communication between WebVIs and LabVIEW applications: WebSockets offers a low-latency and asynchronous communications method between a WebVI and a LabVIEW application. WebSockets client support is available in NXG WebVIs since version 3.1.
- Remote Monitoring: Enabling LabVIEW™ applications with WebSockets allows communication with an application running remotely over a LAN (or WAN/VPN) network. This would allow monitoring/control of applications running in a remote environment (e.g. in a lab/workshop/production area) from the office.
- LabVIEW™ RT / Embedded User Interfaces: Using WebSockets on an RT Target (such as an sbRIO / CompactRIO), stylish user interfaces can be created for embedded targets or products.
- Mobile Interfaces: Most modern smartphones support the WebSockets protocol, allowing bespoke user interfaces for monitoring/control of LabVIEW™ applications from a mobile device such as a phone or tablet.
- Multi-User Interfaces: The WebSockets server can support multiple simultaneous clients, allowing multiple users to interface with the application at the same time.
Download / Installation
The library is published as a VI Package on the NI Tools Network – it can be found in the NI Tools Network repository in VIPM or installed by clicking the link below.
LabVIEW WebSockets API on the NI Tools Network
Source Code – GitHub Repository
The VI Package is supported in LabVIEW™ 2013 or later.
Support for the LabVIEW WebSockets API is provided via the project GitHub page.
For advanced support and implementation/application help – please contact us to discuss paid support options.
Usage / Licensing
The package/source is released under the MIT License. You will be asked to read/accept the license when installing the VI Package.
LabVIEW™ users familiar with the TCP/IP VIs should have no problems integrating the WebSockets API into their applications. The library is a wrapper for the native functions and usage is similar. A simple example of how to use the library is shown below, along with a description of each VI.
The library supports acting as a WebSockets Server. This allows you to write LabVIEW™ that can communicate with a WebSockets client such as a web-browser.
The library also supports acting as a WebSockets Client. You can use the WebSockets Client functionality to talk to a 3rd party WebSockets Server (ws:// only) with LabVIEW™.
New / Upgrade: Opens a new WebSockets connection as a client or upgrades an existing Socket connection to a WebSockets connection.
Handshake: Performs the WebSocket handshaking after a connection is made – reads the headers from the HTTP request and replies with the appropriate WebSocket key to open the connection. Performs the appropriate handshake depending on whether the it is a server or client connection.
Get / Set Header: Sets a send header or reads a header returned from the client/server.
Read Text / Binary: Reads a text or binary frame from the WebSockets connection. Automatically handles Ping/Pong frames and multi-frame messages.
Write Text / Binary: Writes a text or binary frame to the WebSockets connection.
Close: Sends the WebSocket close frame and closes the connection.