Basic WebSocket Server

This app demonstrates a WebSocket server running on the device.

API Features Demonstrated

Platforms

This app works on:

Requirements and Prerequisites

This app requires a ZentriOS evaluation board, such as an AMWx06-E03 (Moray).

Resources

The initialization file settings.ini is packaged into the .zap file downloaded to the device.

The file websocket_server_demo.html is downloaded to the device.

Description

This app demonstrates a WebSocket server running on the device.

The device also runs an HTTP Server that serves out a web page to a client system.

On the client system, entering a message in the demonstration web page Message text box sends the message to the server, which then echoes the result back to the client. The web page displays the echoed message in the Message Log text area.

Instructions for Use

Open a ZentriOS serial terminal to the device. See Getting Started, Opening a ZentriOS Terminal.

This app assumes your ZentriOS device is set up with the credentials to join your local network. If you have not already set up network credentials, on the ZentriOS terminal, run the commands:

network_up -s
save

See the Wi-Fi Command API documentation for network_up and save.

After compiling, downloading and running the app, wait until the device is connected to the local network.

Then in a web browser on a computer or mobile device connected to the same network, open the URL http://websocket_server.local/.

On the WebSocket Demonstration page, in the Device IP or Name text box, specify the name websocket_server and click Open WebSocket

When the Session Log text area displays WebSocket open..., type a message in the Message text box and press Enter.

In the Message Log text area, the messages you send from the WebSocket client are shown in orange. Messages echoed from the WebSocket server are shown in blue.

Implementation

zn_app_init

wlan_network_event_handler

websocket_connect_handler

websocket_disconnect_handler

websocket_receive_handler

Source

See:

See also: