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
ChiaChiaTsao
September 30, 2016
Technology
62
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
websocket 簡介
20160923 前端例會分享
ChiaChiaTsao
September 30, 2016
Transcript
9 slides
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
Other Decks in Technology
See All in Technology
新規事業開発でのAWS活用成功談&失敗談! 〜新規事業開発を専門に行うRelicならではのAWS活用〜
amixedcolor
1
140
セキュリティチームは どのコンテナイメージの脆弱性対応を優先すべきか 〜CISA新指針とSCCで作る脆弱性トリアージ〜
swdtkuy
0
330
技術書典で本を売る流れ
yoshimura_datam
0
130
こんなに変わった! AWSネットワークの常識
shotashiratori
16
11k
Kiro のリモートワークスペース: IDE は手元のままで、ワークスペースをクラウド、コンテナ、自前のマシンに置く
inariku
PRO
1
170
Taking back control of your AI development
inesmontani
PRO
0
310
ポケモンバトルのAIエージェント
koji_kawamura
0
220
【Oracle AI SPOTLIGHT ウェビナー】AI時代、狙われるデータと止められない業務をどう守るか?
oracle4engineer
PRO
1
140
From vibe coding to reliable (agentic) development
jcabot
0
240
ノードが消える前提で設計する!Karpenterで金融システムを止めないためのノウハウ大全
daitak
1
250
エンタープライズIAMについて - ID・権限をどう統制するか
oidfj
1
310
「個社」ではなく「業界」の課題を解く AI 対話開発 ー 価値を広げる設計と、価値を守るエンジニアリング ー
ivry_presentationmaterials
4
860
Featured
See All Featured
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
310
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.5k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
480
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.2k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Utilizing Notion as your number one productivity tool
mfonobong
4
650
Mobile First: as difficult as doing things right
swwweet
225
10k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.7k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
4
1.3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
The agentic SEO stack - context over prompts
schlessera
0
1k