LoginSignup
9
10

More than 5 years have passed since last update.

wscatを使う

Last updated at Posted at 2016-04-05

今回はcommand lineでWebSocketを扱えるwscatを試してみたのでメモっておきます

dockerコンテナ立ち上げ

docker run --rm -it -p 8080:8080 --name wscat-test takashioshikawa/php5.6.17

作業ディレクトリ作成

mkdir /src && cd /src

WebSocketテストをダウンロード

wget https://github.com/TakashiOshikawa/ratchet-test/archive/master.zip

解凍

unzip master.zip
cd ratchet-test-master/

node.jsとnpmのインストール

参考はこちらcentos + node.js + npm + nvm インストール

yum install -y epel-release
yum install -y nodejs
yum install -y npm --enablerepo=epel

wscatのインストール

npm install -g wscat

WebSocketアプリの起動とwscatでの接続

WebSocketアプリをバックグラウンドで実行

php bin/chat-server.php &

wscatで接続

wscat -c localhost:8080/chat

こんな感じの文字が出たらOK

[root@ec5ce01ae845 ratchet-test-master]# wscat -c localhost:8080/chat
New connection! (58)
connected (press CTRL+C to quit)
> dd
Connection 58 sending message "dd" to 0 other connections
> aa
Connection 58 sending message "aa" to 0 other connections
>
9
10
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
9
10