问题描述
我已经创建了一个提供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连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!