文章目录:

推荐一个websocket测试工具:wscat

开发WebSocket程序时,都会需要一个测试环境,用来调试WebSocket的连接和收发消息。

这里推荐一个基于nodejs环境的websocket测试工具:wscat(WebSocket Cat)

官网:https://github.com/websockets/wscat

 

一、安装(windows环境)

1、首先要安装nodejs:http://nodejs.cn/download/

2、在cmd中使用全局安装wscat

cnpm install -g wscat

 

二、作为服务端使用

打开命令窗口,输入命令:wscat -l 8888 (注意是字母L),即可在本地8888端口启动websocket服务监听,此时就已经在你本机中启动了一个websocket服务端程序了。

wscat -l 8888

 

三、作为客户端使用

打开一个新的命令窗口,输入命令:wscat -c ws://localhost:8888,来连接到刚刚创建的websocket服务端。

wscat -c ws://localhost:8888

 

四、命令参数说明

Usage: wscat [options] (--listen <port> | --connect <url>)
Options:
-V, --version output the version number
--auth <username:password> add basic HTTP authentication header (--connect only)
--ca <ca> specify a Certificate Authority (--connect only)
--cert <cert> specify a Client SSL Certificate (--connect only)
--host <host> optional host
--key <key> specify a Client SSL Certificate's key (--connect only)
--max-redirects [num] maximum number of redirects allowed (--connect only) (default: 10)
--no-color run without color
--passphrase [passphrase] specify a Client SSL Certificate Key's passphrase (--connect only). If you don't
provide a value, it will be prompted for
--proxy <[protocol://]host[:port]> connect via a proxy. Proxy must support CONNECT method
--slash enable slash commands for control frames (/ping, /pong, /close [code [, reason]])
-c, --connect <url> connect to a WebSocket server
-H, --header <header:value> set an HTTP header. Repeat to set multiple (--connect only) (default: [])
-L, --location follow redirects (--connect only)
-l, --listen <port> listen on port
-n, --no-check do not check for unauthorized certificates
-o, --origin <origin> optional origin
-p, --protocol <version> optional protocol version
-P, --show-ping-pong print a notification when a ping or pong is received
-s, --subprotocol <protocol> optional subprotocol (default: [])
-w, --wait <seconds> wait given seconds after executing command
-x, --execute <command> execute command after connecting
-h, --help display help for command

 

posted @   网无忌  阅读(15102)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示