Vorrei aggiungere il mio strumento per questo:websocat.
Esempio di sessione con il servizio in questione:
$ rlwrap websocat wss://ws-feed.gdax.com
# Now enter this line (without the #) for the required JSON request:
# {"type":"subscribe","channels": [{ "name": "heartbeat", "product_ids": ["BTC-USD"] }]}
{"type":"subscriptions","channels":[{"name":"heartbeat","product_ids":["BTC-USD"]}]}
{"type":"heartbeat","last_trade_id":46274575,"product_id":"BTC-USD","sequence":6312079752,"time":"2018-07-12T22:32:42.655000Z"}
{"type":"heartbeat","last_trade_id":46274575,"product_id":"BTC-USD","sequence":6312079800,"time":"2018-07-12T22:32:43.656000Z"}
{"type":"heartbeat","last_trade_id":46274575,"product_id":"BTC-USD","sequence":6312079834,"time":"2018-07-12T22:32:44.656000Z"}
{"type":"heartbeat","last_trade_id":46274575,"product_id":"BTC-USD","sequence":6312079945,"time":"2018-07-12T22:32:45.656000Z"}
{"type":"heartbeat","last_trade_id":46274575,"product_id":"BTC-USD","sequence":6312079990,"time":"2018-07-12T22:32:46.657000Z"}
{"type":"heartbeat","last_trade_id":46274575,"product_id":"BTC-USD","sequence":6312080042,"time":"2018-07-12T22:32:47.657000Z"}
{"type":"heartbeat","last_trade_id":46274576,"product_id":"BTC-USD","sequence":6312080169,"time":"2018-07-12T22:32:48.657000Z"}
# To stop the feed, type this line:
{"type":"unsubscribe","channels": [{ "name": "heartbeat", "product_ids": ["BTC-USD"] }]}
{"type":"subscriptions","channels":[]}
Oltre a un client websocket, websocat supporta il server WebSocket e altre modalità e ha lo scopo di integrare i websocket nel mondo "UNIX" in generale.
Bene, puoi provare a imitare le intestazioni richieste per ottenere una risposta usando curl:
- https://gist.github.com/htp/fbce19069187ec1cc486b594104f01d0 o
- Linux Bash:come aprire una connessione websocket come client
Inoltre, ci sono altri modi per comunicare con un server WebSocket, ad es.
- https://github.com/websockets/wscat
- https://github.com/bwasti/webpipe
- https://github.com/progrium/wssh
Supponendo che tu abbia node
installato, darei wscat
un colpo; è semplice , intuitivo e potente . Altrimenti, la risposta di @Pavel ha un'abbondanza di venerabili alternative client websocket.
# install
npm install -g wscat
# use
wscat -c "wss://ws-feed.gdax.com"