The latest development version of this page may be more current than this released 3.7.0 version.

WebSocket Client

Overview

This sample application implements a Websocket client that will do an HTTP or HTTPS handshake request to HTTP server, then start to send data and wait for the responses from the Websocket server.

The source code for this sample application can be found at: samples/net/sockets/websocket_client.

Requirements

Building and Running

You can use this application on a supported board, including running it inside QEMU as described in Networking with QEMU.

Build websocket-client sample application like this:

west build -b <board to use> samples/net/sockets/websocket_client -- -DCONF_FILE=<config file to use>

Enabling TLS support

Enable TLS support in the sample by building the project with the overlay-tls.conf overlay file enabled using these commands:

west build -b qemu_x86 samples/net/sockets/websocket_client -- -DCONF_FILE="prj.conf overlay-tls.conf"

An alternative way is to specify -DEXTRA_CONF_FILE=overlay-tls.conf when running west build or cmake.

The certificate and private key used by the sample can be found in the sample’s samples/net/sockets/websocket_client/src/ directory.

Running websocket-server in Linux Host

You can run this websocket-client sample application in QEMU and run the zephyr-websocket-server.py (from net-tools) on a Linux host. Other alternative is to install websocketd and use that.

To use QEMU for testing, follow the Networking with QEMU guide.

In a terminal window you can do either:

$ ./zephyr-websocket-server.py

or

$ websocketd --port=9001 cat

Run websocket-client application in QEMU:

west build -b qemu_x86 samples/net/sockets/websocket_client -- -DCONF_FILE=prj.conf
west build -t run

Note that zephyr-websocket-server.py or websocketd must be running in the Linux host terminal window before you start the websocket-client application in QEMU. Exit QEMU by pressing CTRL+A x.

Current version of zephyr-websocket-server.py found in net-tools project, does not support TLS.