Linux Bash:如何以客户端身份打开Websocket连接

编程入门 行业动态 更新时间:2024-10-19 00:21:40
本文介绍了Linux Bash:如何以客户端身份打开Websocket连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经创建了一个提供Web套接字服务器的Node.JS应用程序(使用 npm ws ).该websocket等待,直到建立连接.一旦连接命中服务器,Websocket将执行作业.作业完成后,将通过套接字发送一条消息,然后关闭套接字. 该套接字按预期方式工作;已经用另一个Node.JS脚本对其进行了测试.

I have created a Node.JS application that provides a web socket server (using npm ws). This websocket waits until a connection is established. Once a connection hits the server, the websocket executes a job. When the job is done, a message is sent over the socket, then the socket is being closed. This socket works as expected; already tested it with another Node.JS script.

如何仅使用linux 命令行工具连接到网络套接字? 我已经按照此处所述尝试过卷曲.但是,我找不到如何正确连接到运行在localhost:8088/socket/

How can I connect to the web socket using only linux command line tools? I already tried curl as described here. However, I can not find out how to connect properly to my websocket which runs at localhost:8088/socket/

修改: 我的问题被确定为另一个问题的可能重复项.但是,链接的问题仅询问是否有解决卷曲的方法.我很高兴看到任何适用于bash的解决方案.另外,链接问题的答案是使用autobahn.ws

My question has been identified as a possible duplicate of another question. However, the linked question only asks if there is a way to do it with curl. I'd be glad to see any solution which works on bash. Also, the answer to the linked question is a javascript file using autobahn.ws

推荐答案

我的工具 websocat 是专门设计的为此.

My tool websocat is specifically designed for this.

websocat ws://your_server/url

您可以与服务器连接并交换数据.默认情况下,每一行都将成为WebSocket文本消息,反之亦然.

You can connect and exchange data with your server. By default each line becomes a WebSocket text message and vice versa.

在Linux上,使用readline玩起来更舒服:

On Linux it is more comfortable to play with it using readline:

rlwrap websocat ws://your_server/url.

它不是唯一的CLI Websocket客户端.还有"ws"和"wscat"项目.

It is not the only CLI websocket client. There are also "ws" and "wscat" projects.

更多推荐

Linux Bash:如何以客户端身份打开Websocket连接

本文发布于:2023-11-25 23:48:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631830.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   身份   Linux   Bash   Websocket

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!