GNU/Linux >> Belajar Linux >  >> Linux

Cara membaca respons websocket di shell linux

Saya ingin menambahkan alat saya sendiri untuk ini:websocat.

Contoh sesi dengan layanan yang dimaksud:

$ 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":[]}

Selain klien websocket, websocat mendukung server WebSocket dan mode lainnya dan ditujukan untuk mengintegrasikan websockets ke dunia "UNIX" secara umum.


Nah, Anda dapat mencoba meniru tajuk yang diperlukan untuk mendapatkan respons menggunakan curl:

  • https://gist.github.com/htp/fbce19069187ec1cc486b594104f01d0 atau
  • Linux Bash:Cara membuka koneksi websocket sebagai klien

Selain itu, ada cara lain untuk berkomunikasi dengan server WebSocket, mis.

  • https://github.com/websockets/wscat
  • https://github.com/bwasti/webpipe
  • https://github.com/progrium/wssh

Dengan asumsi Anda memiliki node diinstal, saya akan memberikan wscat tembakan; itu sederhana , intuitif , dan kuat . Jika tidak, jawaban @Pavel memiliki banyak sekali alternatif klien websocket terhormat.

# install
npm install -g wscat

# use
wscat -c "wss://ws-feed.gdax.com"

Linux
  1. Bagaimana Cara Membaca Tag Mp3 Di Shell?

  2. Cara Mengganti Shell di Linux

  3. Cara Mengubah Shell Default Di Linux

  1. Cara mengatur variabel $PATH Anda di Linux

  2. Bagaimana cara membaca halaman manual Linux?

  3. Bagaimana cara mengetik karakter khusus di Linux?

  1. Cara mengetik emoji di Linux

  2. Perintah File Linux:Cara Menentukan Jenis File di Linux

  3. Cara menambahkan pengguna ke Linux melalui skrip shell