【WebSocket】工具wscat安装和使用

每当后台服务器部署一个websocket服务需要做测试,测试推流可行性时前后端调试不太方便,可以直接通过命令行工具调试:安装wscat即可。

1,首先安装nodejs

Nodejs安装说明

2,安装wscat

npm install -g wscat (回车创建全局wscat工具)

3,创建websocket服务端

wscat -l 8888

4,创建web socket客户端

wscat -c ws://localhost:8888

5,wscat参数说明

Usage: wscat [options] (--listen  | --connect )
 
Options:
  -V, --version                       output the version number
  --auth           add basic HTTP authentication header (--connect only)
  --ca                            specify a Certificate Authority (--connect only)
  --cert                        specify a Client SSL Certificate (--connect only)
  --host                        optional host
  --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                  connect to a WebSocket server
  -H, --header          set an HTTP header. Repeat to set multiple (--connect only) (default: [])
  -L, --location                      follow redirects (--connect only)
  -l, --listen                  listen on port
  -n, --no-check                      do not check for unauthorized certificates
  -o, --origin                optional origin
  -p, --protocol             optional protocol version
  -P, --show-ping-pong                print a notification when a ping or pong is received
  -s, --subprotocol         optional subprotocol (default: [])
  -w, --wait                 wait given seconds after executing command
  -x, --execute              execute command after connecting
  -h, --help                          display help for command

你可能感兴趣的:(Linux系统,websocket,网络协议,网络)