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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
ChiaChiaTsao
September 30, 2016
Technology
61
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
websocket 簡介
20160923 前端例會分享
ChiaChiaTsao
September 30, 2016
Other Decks in Technology
See All in Technology
Running Kotlin + Quarkus with Lambda
nealle
1
3.8k
古い指輪から広がった JAVA コミュニティ とのつながり
yamad
0
120
事業成長とデータ活用を止めないためのマネジメントへ挑戦
hiracky16
0
390
Claude の新機能を、 出た日に触って社内に届けるまで
rfdnxbro
1
190
パッチ更新でterraform initが落ちた日
grimoh
1
140
パスキーの自動テストはどこまでいけるのか
teamlab
PRO
0
260
実践!Cloud Run ハンズオン!! / Cloud Run handson
y0hgi
2
280
実践! SRE × AI - ABEMA における AIOps -
tetsuya28
8
3.1k
DGX Spark でどこまでハッキングができるのか?
kash1064
3
1.3k
DWH の限界突破! AI エージェント向け爆速リアルタイムデータ基盤 ClickHouse
jozono
1
480
Rust で関数型ドメインモデリング
takonda
0
140
Local CI × GitHub Actions
gogutan
2
220
Featured
See All Featured
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
330
30 Presentation Tips
portentint
PRO
1
430
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
450
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
Building AI with AI
inesmontani
PRO
1
1.3k
Claude Code のすすめ
schroneko
67
230k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
A better future with KSS
kneath
240
18k
How to train your dragon (web standard)
notwaldorf
96
6.9k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
Product Roadmaps are Hard
iamctodd
55
13k
Transcript
Websocket 簡介 20160923 報告人:曹家嘉
Client - Server 如何溝通? HTTP Requset / Response 須由 Client
發起 Requset -> Server 接收後回傳 Response 通常 Server 都是處於被動等待 Client 來要求資料
New feature • Client - Server 雙向溝通 • 快速反應時間越短越好 •
頻繁使用短訊息相互溝通 發展出 Comet 機制 ex: Long polling, Streaming 讓 Client 每隔一段時間對 Server 發出 HTTP Request 來確認 Server 是否有資料回傳
Comet 的問題 • Server 與 Client 之間建立 2 條連線,對Server的負擔極大。 •
Client 需不斷發出 Request 給 Server 確認是否有資料回傳,而 HTTP Request Header 占了大量的 Bytes。 • Client 也需要維持與 Server 的連線資訊來判斷 Server 回傳的資 料並進行動作。
Websocket 的出現 IETF 制定的協定(RFC-6455),W3C 在 HTML5 規範內制定了 WebSocket API的標 準。建立於
HTTP 原有的架構之上,和 HTTP 一樣使用 80 與 443 port。 改善 Comet 的缺點 • 將連線數量減少為一條,全雙工連線。 • 當 Server 有資料更新時,自動傳送給 Client 進行即時更新。 • Header 只有 2 bytes 長度大小。
建立 Websocket 連線 1. Client 發送 HTTP Request 給 Server,並要求
Server 將 HTTP Protocol 更新為 WebSocket Protocol。 2. 待 Server 更新完後即完成了 HandShake,此時 Server 與 Client 就 建立了一條雙向的 WebSocket 連線。 3. 雙方能開始做即時的資料傳輸。
Client API Event & Lifecycle onOpen onClose onError onMessage 連線錯誤
強制中斷 接收資料 關閉連線 資料 錯誤
Websocket 使用例 • 多人協作: Hackpad, trello • 線上多人網頁遊戲: Agar.io •
聊天室: http://socket.io/demos/chat/
Reference • WebSocket – 新一代網路傳輸技術 • When to use a
HTTP call instead of a WebSocket (or HTTP 2.0) • Socket.IO