-
Notifications
You must be signed in to change notification settings - Fork 1
Websocat
Websocat is a versatile command-line tool that enables you to communicate with WebSocket servers and clients with ease. It's perfect for beginners looking to experiment with WebSockets or developers who want to quickly test their WebSocket-based applications.
To get started with Websocat, first, you need to install it. You can find the installation instructions for your specific platform on the Websocat GitHub repository: https://github.com/vi/websocat
Once you have Websocat installed, you can start exploring its features. One of the most common use cases is to send a message to a WebSocket server and receive messages in response.
For example, let's say you want to subscribe to a Nostr relay. Nostr is a decentralized, event-based messaging system built on top of the Hypercore Protocol. You can use the following command with Websocat to subscribe to a Nostr relay:
echo '["REQ", "x", {}]' | websocat -n --ping-interval 20 ws://localhost:4445
In this command:
-
echo '["REQ", "x", {}]'
prepares the subscription request message for the Nostr relay. -
websocat -n --ping-interval 20 ws://localhost:3338/nostr
establishes a WebSocket connection to the Nostr relay running onlocalhost
at port3338
.-
-n
flag tells Websocat to use line-based I/O mode. -
--ping-interval 20
flag sets the ping interval to 20 seconds to keep the connection alive.
-
Once you run this command, you will be subscribed to the Nostr relay, and you'll start receiving messages in your terminal. You can interact with the relay and experiment with different commands to learn more about Nostr and WebSockets.
echo '["REQ", "x", {"kinds":[33334], "authors": ["64401c0577261886bff71b49f22fb35225268f27313fb5af7d5eda7934574746"]}]' | websocat -n --ping-interval 20 ws://localhost:3338
for i in $( cat relays.txt ) ; do echo '["REQ", "x", {"kinds":[0], "authors": ["de7ecd1e2976a6adb2ffa5f4db81a7d812c8bb6698aa00dcf1e76adb55efd645"]}]' | timeout 2 websocat -n --ping-interval 20 $i | tee results.txt ; echo $i ; sleep 1 ; done
websocat -k -v wss://relay.damus.io/ --ping-interval 5
Thank you for visiting our project's wiki! We hope you found the information useful. If you have any questions or suggestions, please feel free to open an issue or submit a pull request. We appreciate your contribution and support!