7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WebSocketのデバック

Last updated at Posted at 2016-08-24

前回RailsのActionCableで作ったチャットアプリにAndroidからデータを投入すべく、リクエスト内容を解析しました。

#1. wscatのインストール
こちらを参考にインストールします。

npm install -g ws

#2. 起動

wscat -c ws://hogehoge:port/

#3. コマンド実行
WireSharkでチャットアプリの通信を記録して、SubscribeとMessage送信部分をそのまま叩いてみます。
<が受信で、>が送信です。

[murotanimari]$ wscat -c ws://mydemos1-1223107232.ap-northeast-1.elb.amazonaws.com:28080/cable
connected (press CTRL+C to quit)
  ### 接続が確率するとwelcomeが返却される
  < {"type":"welcome"}

  ### Pingを定期的に受信
  < {"type":"ping","message":1472068181}

  ### こちらがsubscription要求
  > {"command":"subscribe","identifier":"{\"channel\":\"RoomChannel\"}"}

  ### こちらがsubscription要求の返事
  < {"identifier":"{\"channel\":\"RoomChannel\"}","type":"confirm_subscription"}

  ### こちらがメッセージ送信要求
  > {"command":"message","identifier":"{\"channel\":\"RoomChannel\"}","data":"{\"message\":\"\343\201\213\343\201\213\343\201\213\",\"action\":\"speak\"}"}

  ### こちらがメッセージ受信
  < {"identifier":"{\"channel\":\"RoomChannel\"}","message":{"message":"\u003cdiv class=\"message\"\u003e\n  \u003cp\u003e\343\201\213\343\201\213\343\201\213\u003c/p\u003e\n\u003c/div\u003e\n"}}

若干文字化けしましたがプロセスと書式が分かったので後日利用していきます。

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?