Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

How to make websocket requests from CLI

stainless steel sockets on closeup shot

We normally use cURL requests to easily encapsulate and share HTTP requests with teammates. To perform websocket requests from the CLI, we can make use of websocat, a CLI client for performing websocket requests.

Using websocat to perform websocket requests from the CLI.

Creating a websocket subscription and sending payload

# Create the connection
websocat -t -E tcp-l:127.0.0.1:6543 reuse-raw:ws://your.websocket.com --max-messages-rev 2&

WS_PID=$!

# Send payload, and echo the response
echo '{"id":"1","type": "stop"}' | nc ${LOCALHOST} ${LOCALPORT}

# Close the connection
kill ${WS_PID}

Command line result

Result of the command would look something like this:

The full source code for this is available on Gist GitHub.

You can also check out my other tech-related posts and tutorials.

Explore, Learn, and Thrive: Tech and Gaming with Darren

Hello, reader! I’m Darren, and I’m passionate about technology, learning, and gaming. My articles cater to mid to senior-level software engineers seeking to expand their knowledge and skills.

Through sharing our experiences and lessons learned (including our mistakes), we can inspire, support, and empower the next generation of engineering problem solvers. Documenting these insights also helps me reinforce their importance and ensure they remain in my memory.

In my blog, you’ll find a collection of mental models designed to help you tackle challenges in both your engineering career and personal life. Additionally, I share personal reflections and short stories, exploring parallels between competitive gaming and workplace performance.

Join me on this journey to learn and grow together!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.