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.
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_linux64
Set execute permission:
sudo chmod a+x /usr/local/bin/websocat
websocat will be available for all users as a system-wide command.
We can check Websocat version as follows:
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:
Now you can type something and press the Enter key. A server will send the same message back.
Press CTRL+C to quit.
-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:
If you wish to remove Websocat, delete the executable file:
sudo rm -rf /usr/local/bin/websocat