This is the documentation for the latest (main) development branch of Zephyr. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.

Civetweb WebSocket Server sample


This sample application uses the HTTP APIs provided by the external Civetweb module to create an WebSocket server demonstrating selected Civetweb features. The Civetweb module is available as a west module.

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


  • A board with hardware networking

  • The Civetweb module (made available via west)

Building and Running

This sample was tested on the NUCLEO H745ZI-Q board, so this is the recommended target.

Build it with:

west build -b nucleo_h745zi_q_m7 samples/net/civetweb/websocket_server

The sample application uses a static IP configuration.

After flashing the board, the server can be accessed with the web browser of your choice (preferably Chrome) under IPv4 address. The IP address can be changed in samples/net/civetweb/websocket_server/prj.conf The port number can be changed in samples/net/civetweb/websocket_server/main.c

This sample application consists of two main parts:

  • HTTP Server - or It is needed to serve application’s main page and its dependencies.

  • WebSocket Server - ws:// It is an echo server, which sends recived data enclosed in board name and a string too! back.

The HTTP Server* serves following statically allocated files (no file system is present):

  • / - main application page (redirects requests to /index.html)

  • /index.html - main application page

  • /index.css - main application page style sheet

  • /ws.js - WebSocket client JavaScript

A regular 404 status code is returned when trying to access other links.

The WebSocket Server works as follows:

Calling the in your browser provides WebSocket client JavaScript load. This script establishes the connection to the WebSocket server running on your board. Putting some message in `Message Text` window and pressing Send button generates predefined answer from WebSocket server printed in log window.