Install Websocat on Raspberry Pi

Install Websocat on Raspberry Pi

WebSocket is a two-way communication protocol over a TCP. Websocat is a tool that enables to use WebSocket client or server from the command line. It can operate in client mode and connect to WebSocket server or operate in server mode and accept connections from WebSocket clients.

This tutorial explains how to install Websocat on Raspberry Pi.

Install Websocat

Connect to Raspberry Pi via SSH. Download the latest Websocat release from GitHub to the /usr/local/bin directory.

sudo wget -qO /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.arm-unknown-linux-musleabi

Next, add execute permission to the downloaded file:

sudo chmod a+x /usr/local/bin/websocat

Websocat is available for all users as a system-wide command. We can check Websocat version:

websocat --version

Testing Websocat

In order to connect to WebSocket server, execute websocat command and provide server URL as argument. For example, connect to public WebSocket echo server with command:

websocat wss://echo.websocket.events

Now type something and press the Enter key. A server will send the same message back.

Connect to WebSocket Server Using Websocat

Press CTRL+C to quit.

Use -s option to start WebSocket server. Provide the port number as argument.

websocat -s 8080

Now open another terminal on your machine and connect to the Raspberry Pi. Then run the following command to connect to local WebSocket server:

websocat ws://127.0.0.1:8080
Accept Connections From WebSocket Clients Using Websocat

Uninstall Websocat

If you want to remove Websocat, just delete the binary file with command:

sudo rm -rf /usr/local/bin/websocat

Leave a Comment

Cancel reply

Your email address will not be published.