GNU/Linux >> Linux Esercitazione >  >> Linux

Come leggere la risposta websocket nella shell linux

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"

Linux
  1. Come impostare la tua variabile $PATH in Linux

  2. Come leggere i tag Mp3 in Shell?

  3. Come cambiare la shell in Linux

  4. Come modificare la shell predefinita in Linux

  5. Come aggiungere utenti a Linux tramite uno script di shell

Come avviare Fish Shell in modalità privata in Linux

Come determinare il tipo MIME di un file in Linux

Come memorizzare un comando Linux come variabile nello script della shell

Come installare Linux Bash Shell su Windows 10

Come modificare una shell utente in Linux

Come installare e utilizzare Nu Shell su Linux