Post

Websocat

WebSocat

  • 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.

Installation

  1. Install Websocat
    • Download the latest Websocat executable file from the releases page in GitHub repository:
      1
      
      sudo wget -qO /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl
      
  2. Set execute permission:
    1
    
    sudo chmod a+x /usr/local/bin/websocat
    
  3. Now websocat will be available for all users as a system-wide command. Check the version using the below command:
    1
    
    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:
    1
    
    websocat wss://echo.websocket.events
    
  • Now you can type something and press the Enter key. A server will send the same message back.
1
2
3
4
5
6
user@linuxhost:~$ websocat wss://echo.websocket.events
echo.websocket.events sponsored by Lob.com
Hellow
Hellow
ABC
ABC

Press CTRL+C to quit.

Testing Locally:

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

2: Now open another terminal on your system and run the following command to connect to local WebSocket server:

1
websocat ws://127.0.0.1:8080

Uninstall Websocat

  • If you wish to remove Websocat, delete the executable file:
    1
    
    sudo rm -rf /usr/local/bin/websocat
    
This post is licensed under CC BY 4.0 by the author.