Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
WebSocketの調査
Search
株式会社イノベーション(エンジニア)
March 03, 2025
35
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
WebSocketの調査
株式会社イノベーション(エンジニア)
March 03, 2025
More Decks by 株式会社イノベーション(エンジニア)
See All by 株式会社イノベーション(エンジニア)
PRのCI稼働時間を7割削減した話
innovationjp
0
9
翻訳用の Chrome 拡張を作った
innovationjp
0
9
zenn-writer-skill が 素晴らしかった話 - 質問に答えていたら、記事ができていた -
innovationjp
0
9
エンジニアが事業側に⾏って、 考える順番が変わった
innovationjp
0
95
Go 1.27 リリース解説 メモリ最適化・JSON v2・待望のジェネリックメソッド解説
innovationjp
0
23
MoQT フルスクラッチ実装
innovationjp
0
20
月18万行の コーディングを行った話
innovationjp
0
8.5k
アイデア枯渇から救った 1匹の猫の話
innovationjp
0
32
『問題解決』を読んでSkillにしてみた
innovationjp
0
500
Featured
See All Featured
Mind Mapping
helmedeiros
1
440
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
890
Bash Introduction
62gerente
615
220k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.9k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
2
440
So, you think you're a good person
axbom
PRO
2
2.3k
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
For a Future-Friendly Web
brad_frost
184
11k
Visualization
eitanlees
153
17k
Large-scale JavaScript Application Architecture
addyosmani
516
110k
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接続まで。