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.
Connect to Raspberry Pi via SSH. Download the latest Websocat release from GitHub to the
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:
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:
Now type something and press the Enter key. A server will send the same message back.
Press CTRL+C to quit.
-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:
If you want to remove Websocat, just delete the binary file with command:
sudo rm -rf /usr/local/bin/websocat