SlideShare a Scribd company logo
Hao-kang Den @_hden
Socket.io under the hood
Socket.io under the hood
Agenda
● Why socket.io?
● What’s socket.io? What’s websocket?
● Socket.io in detail
HTTP
serverclient
(1) request
(2) response
WTF?
X
Bi-directional Communication
serverclient
(1) signal
(2) acknowledgement
(3) signal
(4) acknowledgement
Why don’t we use websocket?
● Standardized by
○ RFC 6455
○ W3C
● IE9 says NO
Why socket.io?
+ native iOS & Android
Socket.io Communication Layers
API
packet
communication (ws, jsonp, etc.)
Socket.io under the hood
API
# client
socket.emit(‘foo’, param1, param2, ...)
socket.on ‘bar’, (param1, param2, ...) ->
console.log(‘yay got a bar!’)
# server
socket.on ‘foo’, (param1, param2, ...) ->
console.log(‘yay got a foo!’)
socket.emit(‘bar’, param1, param2, ...)
Packet
socket.emit(‘foo’, param1, param2, ...)
# socket.io v0.9.x
packet = {
type: ‘event’
id: ‘unique packet id’
name: ‘foo’
args: [param1, param2, ...]
}
# socket.io v1.0.x
packet = {
type: ‘event’
id: ‘unique packet id’
name: ‘foo’
data: [param1, param2, ...]
}
https://github.com/LearnBoost/socket.io-protocol
Communication Layer
# socket.io v0.9.x
packet = {
type: ‘event’
id: 1
name: ‘foo’
args: [param1, param2, ...]
}
# socket.io v0.9.x
5:1::{“name”:”foo”,”args”:[param1, param2, ...]}
https://github.com/LearnBoost/socket.io-spec
Further Reading
● http://davidwalsh.name/websocket
● test/spec https://github.com/LearnBoost/socket.io/blob/master/test/socket.io.js
● code https://github.com/LearnBoost/socket.io/blob/master/lib/socket.js
read!

More Related Content

KEY
Going real time with Socket.io
KEY
Socket.io
PDF
Socket.IO
PDF
Going realtime with Socket.IO
PDF
Socket.io (part 1)
KEY
Socket.io
PDF
Socket.IO - Alternative Ways for Real-time Application
PPT
Real Time Communication using Node.js and Socket.io
Going real time with Socket.io
Socket.io
Socket.IO
Going realtime with Socket.IO
Socket.io (part 1)
Socket.io
Socket.IO - Alternative Ways for Real-time Application
Real Time Communication using Node.js and Socket.io

What's hot (20)

KEY
Node worshop Realtime - Socket.io
PDF
web3j Overview
PDF
Web3j 2.0 Update
PDF
Building Java and Android apps on the blockchain
PPTX
node.js workshop- node.js basics
PPTX
Ember and WebSockets
PDF
Service Discovery for Continuous Delivery with Docker
PDF
How do I construct a python web server using this code? #import socket modul...
PDF
Realtime web applications with ExpressJS and SocketIO
PDF
Socket.io tech talk 06022014
PPTX
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014
KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
PPTX
Codable routing
PDF
Creating an Arduino Web Server from scratch hardware and software
PDF
aiohttp intro
PDF
Ingredients for creating dapps
PPTX
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...
PDF
Why async matters
PDF
WebSockets, Unity3D, and Clojure
PDF
Java and the blockchain - introducing web3j
Node worshop Realtime - Socket.io
web3j Overview
Web3j 2.0 Update
Building Java and Android apps on the blockchain
node.js workshop- node.js basics
Ember and WebSockets
Service Discovery for Continuous Delivery with Docker
How do I construct a python web server using this code? #import socket modul...
Realtime web applications with ExpressJS and SocketIO
Socket.io tech talk 06022014
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Codable routing
Creating an Arduino Web Server from scratch hardware and software
aiohttp intro
Ingredients for creating dapps
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...
Why async matters
WebSockets, Unity3D, and Clojure
Java and the blockchain - introducing web3j
Ad

Similar to Socket.io under the hood (20)

PPTX
Socket.io v.0.8.3
PPTX
Socket.io v.0.8.3
PDF
Socket.IO
PPTX
Socket.pptx
PDF
Nodejs and WebSockets
PPTX
PDF
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
ODP
SockJS Intro
PDF
How to create a real time chat application using socket.io, golang, and vue js-
PDF
CommandBox WebSockets - and SocketBox.pdf
PPTX
socket.io on SmartFx
PPTX
Intro to WebSockets
PPTX
Websockets in Node.js - Making them reliable and scalable
PDF
Unveil the Power of Socket.IO in Node.js
PPTX
Web sockets Introduction
PDF
Web in real time - technical project - socket.io
PPTX
Basic understanding of websocket and and REST API
PPTX
ClientServer Websocket.pptx
PDF
How to build a chat application with react js, nodejs, and socket.io
PDF
how to develop a serverless in-app notification system - beSharp serverlessda...
Socket.io v.0.8.3
Socket.io v.0.8.3
Socket.IO
Socket.pptx
Nodejs and WebSockets
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
SockJS Intro
How to create a real time chat application using socket.io, golang, and vue js-
CommandBox WebSockets - and SocketBox.pdf
socket.io on SmartFx
Intro to WebSockets
Websockets in Node.js - Making them reliable and scalable
Unveil the Power of Socket.IO in Node.js
Web sockets Introduction
Web in real time - technical project - socket.io
Basic understanding of websocket and and REST API
ClientServer Websocket.pptx
How to build a chat application with react js, nodejs, and socket.io
how to develop a serverless in-app notification system - beSharp serverlessda...
Ad

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation theory and applications.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
A Presentation on Touch Screen Technology
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
Tartificialntelligence_presentation.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation theory and applications.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
Heart disease approach using modified random forest and particle swarm optimi...
A Presentation on Touch Screen Technology
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Chapter 5: Probability Theory and Statistics
Tartificialntelligence_presentation.pptx
A comparative analysis of optical character recognition models for extracting...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Programs and apps: productivity, graphics, security and other tools
WOOl fibre morphology and structure.pdf for textiles
Agricultural_Statistics_at_a_Glance_2022_0.pdf
1 - Historical Antecedents, Social Consideration.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
TLE Review Electricity (Electricity).pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia

Socket.io under the hood