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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
株式会社イノベーション(エンジニア)
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
2
翻訳用の Chrome 拡張を作った
innovationjp
0
2
zenn-writer-skill が 素晴らしかった話 - 質問に答えていたら、記事ができていた -
innovationjp
0
2
エンジニアが事業側に⾏って、 考える順番が変わった
innovationjp
0
6
Go 1.27 リリース解説 メモリ最適化・JSON v2・待望のジェネリックメソッド解説
innovationjp
0
18
MoQT フルスクラッチ実装
innovationjp
0
18
月18万行の コーディングを行った話
innovationjp
0
8.5k
アイデア枯渇から救った 1匹の猫の話
innovationjp
0
31
『問題解決』を読んでSkillにしてみた
innovationjp
0
450
Featured
See All Featured
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
560
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
540
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Speed Design
sergeychernyshev
33
2.2k
The World Runs on Bad Software
bkeepers
PRO
72
12k
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接続まで。