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
Socket.IO Introduction
Search
orisano
December 04, 2018
Technology
3.3k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Socket.IO Introduction
orisano
December 04, 2018
More Decks by orisano
See All by orisano
OSS Performance Tuning Tips
orisano
8
6.2k
Docker-Compose & BuildKit
orisano
4
1.1k
Container Build Talk
orisano
3
2.6k
dockerignore talk
orisano
2
7.4k
Better docker image+
orisano
6
6.7k
Profiling Go Application
orisano
11
8.1k
Multi-stage Builds Patterns & Practice
orisano
6
5.3k
better docker image
orisano
22
31k
the world of characters
orisano
8
1.5k
Other Decks in Technology
See All in Technology
ラジオの科学
frievea
0
310
【CEDEC2026】Creative Approaches to Localizing the Dialects and Unique Speech of Umamusume: Pretty Derby Characters in English
cygames
PRO
3
20k
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
4.9k
メルカリのグローバルアプリで挑んだ AlloyDB 運用と課題解決の実践記
hatappi
0
250
オートロックマンションなのに、各部屋は施錠なし!? 攻撃者が組織内ネットワークで大暴れする理由 / The Front Door Is Locked, but the Rooms Are Wide Open: Why Attackers Move Freely Inside Enterprise Networks
nttcom
1
4k
MulticaとPi Coding Agentで、小規模OSSを30本同時運用した流れ
eiei114
0
110
モノリス Rails でも日中に rails db:migrate を走らせたい! / Daytime rails db:migrate on Monolithic Rails!
euglena1215
4
580
『三匹の子ぶた』から学ぶネットワークセキュリティの昔と今 / Network Security: Then and Now Through the Lens of The Three Little Pigs
nttcom
1
4.1k
取引先から届く 「セキュリティチェックシート」の読み解き方
kamadamakoto
0
150
モバイルアプリ開発概論2026
recruitengineers
PRO
5
590
Flutterをカメラで動かしたかった話
sony
1
140
【CEDEC2026】グラフィックスエンジニアのためのニューラルシェーディング入門
cygames
PRO
0
150
Featured
See All Featured
Leo the Paperboy
mayatellez
8
2.1k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
430
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
460
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
640
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
470
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.8k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
240
Abbi's Birthday
coloredviolet
3
9.3k
Tell your own story through comics
letsgokoyo
1
1k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
430
Transcript
Socket.IOʹೖͨ͠ @orisano
Socket.IOͬͯΔਓ
Socket.IOͬͨ͜ͱ͋Δਓ
Socket.IOΕΔਓ
ΰʔϧ Socket.IO͕ΕΔΑ͏ʹͳΔ
ͦͦSocket.IOͱ
Socket.IO • FEATURING THE FASTEST AND MOST RELIABLE REAL-TIME ENGINE
• ૣͯ͘৴པͰ͖ΔϦΞϧλΠϜΤϯδϯ • ϦΞϧλΠϜͰํͷevent-basedͳ௨৴
Socket.IO • Node.jsͰ࣮͞Ε͍ͯΔ • ࠓversion 2.0 • ϒϥβͰϦΞϧλΠϜ௨৴ͳΒ͜Εͱ͍͏ • ΩϥʔΞϓϦͩͬͨ
Α͋͘Δޡղͱͯ͠ Socket.IO == WebSocket
Socket.IO !== WebSocket
Socket.IO • Ή͠ΖWebSocketͷରԠঢ়گ͕ѱ͔ͬͨ࣌ظ ʹಉ༷ͷ͜ͱΛ͢ΔͨΊͷͷͩͬͨ • TransportWebSocketͰͳͯ͘Α͍ • TransportEngine.IOͰநԽ͞Ε͍ͯΔ
Engine.IO • Socket.IOͷͨΊʹ࡞ΒΕͨRealtime Engine • ௨৴ϨΠϠʔ·Ͱ͔͠ݟͳ͍ • eventͱ͔ͦ͏͍͏ػೳଘࡏ͠ͳ͍
Engine.IO • WebSocket [packet] • Polling [payload] • XMLHttpRequest •
JSONP • MUST support three transport
8FC4PDLFU 9.-)UUQ3FRVFTU +40/1 &OHJOF*0 4PDLFU*0 #SPXTFS$MJFOU
͑ͬ໘ष͞ ࠓͷ࣌ WebSocketͰ͍͍Ͱ͠ΐ
https://blog.jxck.io/entries/ 2016-08-22/websocket- connectivity.html
·ͱΊ • RFCʹଇͬͨWebSocketIE11͔Β • Connection: UpgradeΛམͱ͢ϛυϧϘοΫε • HTTPͰ࣌ؒுΓͬͺͳ͠ͷίωΫγϣϯΛ ΔϛυϧϘοΫε
·ͱΊ • RFCʹଇͬͨWebSocketIE11͔Β • Connection: UpgradeΛམͱ͢ϛυϧϘοΫε • HTTPͰ࣌ؒுΓͬͺͳ͠ͷίωΫγϣϯΛ ΔϛυϧϘοΫε IEͬͯͳΜͰ͔͢ʁ
·ͱΊ • RFCʹଇͬͨWebSocketIE11͔Β • Connection: UpgradeΛམͱ͢ϛυϧϘοΫε • HTTPͰ࣌ؒுΓͬͺͳ͠ͷίωΫγϣϯΛ ΔϛυϧϘοΫε IEͬͯͳΜͰ͔͢ʁ
҉߸Խ͢Εͳ͍Ͱ͢. wssΛ͏.
·ͱΊ • RFCʹଇͬͨWebSocketIE11͔Β • Connection: UpgradeΛམͱ͢ϛυϧϘοΫε • HTTPͰ࣌ؒுΓͬͺͳ͠ͷίωΫγϣϯΛ ΔϛυϧϘοΫε IEͬͯͳΜͰ͔͢ʁ
҉߸Խ͢Εͳ͍Ͱ͢. wssΛ͏. Ͳ͏ʹͳΒͳ͍
·ͱΊ • ࣮ࡍͲͷఔଘࡏ͢Δͷ͔Θ͔Βͳ͍ • ͍ΜͨʔͶͬͱ͍͠ͷͰଞͷݪҼ͋Δ • ϦΞϧλΠϜ௨৴͕؊Ͱ͍ΖΜͳڥͷϢʔβ ʹͬͯΒ͍͍ͨ߹Socket.IO
େઢ͠·͕ͨ͠
Socket.IOΛΔʹ
8FC4PDLFU 9.-)UUQ3FRVFTU +40/1 &OHJOF*0 4PDLFU*0 #SPXTFS$MJFOU
ਓ͕ؒ WebSocketΔͷ “””͍͠”””
ͦΕΑΓ্ͷϨΠϠʔ ͱ͍͏͜ͱʹ͠·͢
8FC4PDLFU 9.-)UUQ3FRVFTU +40/1 &OHJOF*0 4PDLFU*0 #SPXTFS$MJFOU
·ͣEngine.IOΛΔ
Engine.IO • https://github.com/socketio/engine.io-protocol • ࠓrevision: 3 • ͘͢͝γϯϓϧͰ໋ྩ͕7छྨ͔͠ͳ͍ • <packet
type id>[data] ୯७ͳformat
Engine.IO • 0 open, αʔό͔Β࠷ॳʹૹΒΕͯ͘Δ • 1 close, அ͢Δͱ͖ʹૹΔ •
2 ping, ͪ͜Β͔ΒૹΔੜଘใࠂ • 3 pong, pingΛड͚औͬͨ࣌ʹαʔό͔Βฦͬͯ͘Δ • 4 message, σʔλΛૹड৴͢Δ࣌ʹ͏ • 5 upgrade, transportΛม͑Δ࣌ʹૹΔ • 6 noop, ͳʹ͠ͳ͍
git clone https://github.com/orisano/socketio-handson cd socketio-handson npm i npm run serve:eio
npm run conn:eio
Engine.IO • < 0******* // open • > 2 //
ping • < 3 // pong • > 4hello. engine.io // message • < 4reply:hello
͜ΕͰEngine.IOᘳ
͋ͱSocket.IO͕ΕΕ
Socket.IO • https://github.com/socketio/socket.io-protocol • ࠓrevision: 4 • ͘͢͝γϯϓϧͰ໋ྩ͕7छྨ͔͠ͳ͍ • formatͷৄࡉʹ͍ͭͯ͋·Γॻ͍ͯͳ͍
Socket.IO • socket.io-parserͷ࣮ΛݟΔ • <packet type id>[(attachments)-] [(namespace:/),][id][data] • ͏Μ,
simple
Socket.IO • 0 CONNECT, αʔό͔Β࠷ॳʹૹΒΕͯ͘Δ • 1 DISCONNECT, அ͢Δͱ͖ʹૹΔ •
2 EVENT, Πϕϯτ͕ى͖ͨ࣌ʹૹड৴͢Δ • 3 ACK,ಛఆͷύέοτʹରͯ͠ฦ৴͢Δ࣌ʹ͏ • 4 ERROR,Τϥʔ͕ى͖ͨ࣌ʹ͏ • 5 BINARY_EVENT, όΠφϦΛૹΔ࣌ͬͪ͜ • 6 BINARY_ACK, όΠφϦΛฦ࣌ͬͪ͢͜
npm run serve:sio npm run conn:sio
Socket.IO • > 0 // e:open • > 40 //
e:message s:connect • < 42[“message”,”hello”] // e:message s:event data • > 42[“reply”,”?hello”] // e:message s:event data • < 41 // e:message s:disconnect • < 42[“message”,”hello”] // e:message s:event data • < 40 // e:message s:connect • < 42[“message”,”hello”] // e:message s:event data • > 42[“reply”,”?hello”] // e:message s:event data
͜ΕͰSocket.IOᘳ
ͦͦ
ͳΜͰSocket.IOͷʁ
https://github.com/orisano/gomasio socket.io-clientͷgolang࣮Λ ࡞ͬͨͷͰએ