#要約
WebSocket通信のクライアント/サーバの環境を構築する。お仕事でWebSocket通信のツール、環境が必要となった際にまとめたものです。
wsのインストール
~/develop/wscatTest $ yarn init
yarn init v1.22.5
question name (wscatTest):
question version (1.0.0):
question description:
question entry point (index.js):
question repository url:
question author:
question license (MIT):
question private:
success Saved package.json
✨ Done in 2.88s.
~/develop/wscatTest $ yarn add ws
yarn add v1.22.5
info No lockfile found.
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 🔨 Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ ws@8.3.0
info All dependencies
└─ ws@8.3.0
✨ Done in 1.40s.
~/develop/wscatTest $
サーバ環境構築
~/develop/wscatTest $ npx wscat -l 3000
Listening on port 3000 (press CTRL+C to quit)
クライアント接続
~/develop/wscatTest $ npx wscat -c ws://localhost:3000
Connected (press CTRL+C to quit)