Install Websocat on Ubuntu 20.04

Install Websocat on Ubuntu 20.04

WebSocket is a two-way communication protocol over a TCP. Websocat is a tool that allows to use WebSocket client or server via 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 shows how to install Websocat on Ubuntu 20.04.

Install Websocat

Download the latest Websocat executable file from the releases page in GitHub repository:

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

Set execute permission:

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

Now websocat will be available for all users as a system-wide command.

We can check Websocat version as follows:

websocat --version

Testing Websocat

We can run the websocat command and provide WebSocket server URL as argument to connect to the server. For example, the following command connects to public WebSocket echo server:

websocat wss://echo.websocket.events

Now you can 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.

The -s option can be used to start WebSocket server. Provide the port number as argument.

websocat -s 8080

Now open another terminal on your system and 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 wish to remove Websocat, delete the executable file:

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

Leave a Comment

Cancel reply

Your email address will not be published.