Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
WebSocketの調査
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
株式会社イノベーション(エンジニア)
March 03, 2025
1
22
WebSocketの調査
株式会社イノベーション(エンジニア)
March 03, 2025
Tweet
Share
More Decks by 株式会社イノベーション(エンジニア)
See All by 株式会社イノベーション(エンジニア)
新規事業で「Spec駆動開発」を 導入したら、開発よりもSpec修 正で死んだ話
innovationjp
0
32
ITトレンドのフロントエンドNext.js移行までの道のり
innovationjp
2
1.8k
Windsurf使ってみて
innovationjp
0
14
Goの日時書式の話
innovationjp
0
250
スプリントで回すデータ基盤運用
innovationjp
0
15
Google Professional Data Engineer をとったよ
innovationjp
0
13
社内工数入力を促すための挑戦
innovationjp
1
380
Featured
See All Featured
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
The Language of Interfaces
destraynor
162
26k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
420
Building the Perfect Custom Keyboard
takai
2
680
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
940
Marketing to machines
jonoalderson
1
4.6k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
3.9k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Designing for Timeless Needs
cassininazir
0
130
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
Transcript
websocketについて 土方宏太郎
websocketとは? HTTP:クライアント(ブラウザ)がリクエストを送 り、サーバーがレスポンスを返す WS(WebSocket):WebSocket は、クライアントとサーバ ー間で双方向通信を可能にするプロトコル。一度接続が確立さ れると、その後はクライアントとサーバーが自由に情報を送受 信できます。 例:チャットアプリ、ゲームやトラッキングシステム、株価やリアルタイムデー タの更新。
リクエスト ブラウザ サーバー サーバー ブラウザ websocketリクエスト レスポンス 双方向通信 websocketコネクション HTTP
websoket wss://ws-ap3.pusher.com/app/
山田のブラウザ webサーバー 送信 pusherサーバー 実践:Pusherを使って、チャット機能を実装 田中のブラウザ 鈴木のブラウザ webSocket メッセージを 任意のチャンネルにブロードキャスト(送信)
http/https webSocket webSocket
クライアント webサーバー connection subscription 接続 購読 リッスン 接続リクエスト 購読リクエスト(channel:chat) 接続成功(socket_id)
購読成功 pusherサーバー イベントをブロードキャスト (MessageSent) 実装:イベントを受け取るまでの流れ ① ②
None
Pusherにログイン セットアップ
諸々セッティング。 (環境変数、ルーティング) コード解説①
サイト読み込み時にクライアントからpushserサーバー へ接続確立’connection) コード解説②
None
チャット画面 コード解説③ 送信処理&リスナー
None
webサーバからpusherサーバーのチャンネルにイベントをブロード キャスト(送信)する コード解説④
None
None
None
特徴 パブリックチャネル プライベートチャネル アクセス制限 誰でもアクセス可能 認証されたユーザーのみアクセ ス可能 認証が必要か 不要 必要
データの保護 保護されない(全ての購読者に 通知される) 認証されたユーザーのみ通知を 受け取る 使用例 公開チャット、通知システム 個人チャット、ユーザー専用ダ ッシュボード ソケットIDの利用 使用しない 認証プロセスで利用(リクエス トに含められる) パブリックチャンネルだと誰でもチャッ トを受信できてしまう・・・ 🥺
クライアント webサーバー connection subscription 購読 リッスン 接続リクエスト 購読リクエスト broadcat/authへPOST 接続成功(socket_id)
購読成功 Jsonレスポンス {auth: key generate} {auth: key generate, channel:chat} 接続 (channnel_name,socket_id) pusherサーバー イベントをブロードキャスト (MessageSent) イベントを受け取るまでの流れ -プライベートチャンネル 認証ロジック
発展編
〇〇さんが入力しています・・・と表示する PusherのWisperを使って 山田のブラウザ ブロードキャストより 高速 🥺 pusherサーバー 田中のブラウザ webサーバー メッセージ入力すると
{typer: ‘田中一郎’ typingイベント {typer: ‘田中一郎’
UI Whisperの実装
認証ロジック追加
プライベートチャンネルに送信
None
None
ご清聴ありがとうございました!
メッセージ数:月間200,000メッセージまで。 Pusherの無料プラン 同時接続数:最大100接続まで。