2
Most read
4
Most read
8
Most read
WebSockets
Julien	LaPointe
What	is	a	WebSocket?
• Communication	protocol	used	to	send	/	receive	data	on	the	Internet
• Like	HTTP,	but	on	steroids...	WebSockets	are	wayyy	more	efficient
• Persistent	2-way connection	between	browser	<-->	server
• Easy	to	build	real-time applications:
• Chat
• Notifications
• Online	games
• Financial	trading
• Data	visualization	dashboards
• Live	maps
• Collaboration	apps
Half-duplex	(like	walkie-talkie) Full-duplex	(like	phone)
Traffic	flows	in	1	direction	at	a	time Bi-directional	traffic	flow
HTTP WebSocket
Roger	that.
Over	and	out...
...Who’s	Roger? I	knooooww
Right??!!!
Like	
totalllyyyy
For	real??
Half-duplex	(like	walkie-talkie) Full-duplex	(like	phone)
Traffic	flows	in	1	direction	at	a	time Bi-directional	traffic	flow
Connection	is	typically	closes after	1	
request	/	response	pair
Connection	stays	open
1.	Request from	client to	server
2.	Response from	server	to	client
Both	client	and	server	are	
simultaneously “emitting”	and	
“listening”	(.on	events)
Headers	(1000s of	bytes) Uses	“frames”	(2	bytes)
150ms to	establish	new	TCP	connection	
for	each	HTTP	message
50ms for	message	transmission
Polling	overhead	(constantly	sending	
messages to	check	if	new	data	is	ready)
No	polling	overheard	(only	sends	
messages	when	there	is	data	to	send)
HTTP WebSocket
Life	Before	WebSockets...
Are	we	
there	
yet?
Are	we	
there	
yet?Are	we	
there	
yet?
Are	we	
there	
yet?Are	we
there
yet?
• Simulate	real-time	
communication	with HTTP
• AJAX: browser	sends	requests	at	
regular	intervals	to	check	for	
updates	
but	headers	cause	latency	and	
polling	is	very	resource	intensive
• Comet:	server	push	technique	
but	complex,	non-standardized	
implementation
• Streaming: more	efficient	than	
AJAX	and	Comet	
but	only	1	direction
How	do	WebSockets	work?
Heroku	Server
Your	Phone
Your	Computer
1. Client	sends	HTTP	GET	request	to	URL		
(https://socketio-experimentia.herokuapp.com/)
How	do	WebSockets	work?
Heroku	Server
Your	Phone
Your	Computer
2. Server	responds	with	requested	files,	which	include	
information	for	connecting	to	socket	server
1. Client	sends	HTTP	GET	request	to	URL		
(https://socketio-experimentia.herokuapp.com/)
How	do	WebSockets	work?
Heroku	Server
Your	Phone
Your	Computer
2. Server	responds	with	requested	files,	which	include	
information	for	connecting	to	socket	server
1. Client	sends	HTTP	GET	request	to	URL		
(https://socketio-experimentia.herokuapp.com/)
3. Client	sends	HTTP	GET	request	with	“Connection:	
Upgrade”	in	the	header,	server	confirms	support,	and	
connection	is	upgraded	to	WebSockets																												
(called	the	“handshake”)	until	one	side	disconnects
Is	there	ANYTHING bad	about	WebSockets?
• Not	all	browsers	support	WebSockets
• Different	browsers	treat	WebSockets	differently
Released	March	8,	2017
First	supported	March	2,	2016
Support	as	of	March	8,	2017
Socket.io
• 2	JavaScript	libraries:
• socket.io-client	(front-end)
• socket.io (back-end	using	NodeJS)
• Cross-browser	compatibility	by	automatically	using	the	best	protocol	
for	the	user’s	browser
• WebSockets
• Comet
• Flash
Socket.io Server	Configuration
// add the HTTP server
var http = require('http');
// add Express server framework for NodeJS
var express = require('express');
// add Socket.io server framework
var socketIO = require('socket.io');
// create instance of Express
var app = express();
// create Express HTTP server
var server = http.createServer(app);
// tell Express HTTP server which port to run on
server.listen(8080);
// tell Socket.io to add event listeners to Express HTTP server
var io = socketIO().listen(server);
1.	Create	HTTP	server
2.	Add	WebSocket	support	
to	HTTP	server
Socket.io Server	Code
// listens for new socket connections from clients
// triggers a callback function when ‘connection’ event occurs
io.sockets.on('connection', function(socket) {
// do stuff (ex. keep track of # of socket connections)
connections.push(socket);
// emit / broadcast custom event and data (payload) to client
io.sockets.emit(’updateStudents', payload);
}
// listen for custom events “emitted” by client
socket.on('join', function(payload) {
var newStudent = {
socketID: this.id,
name: payload.name
}
this.emit('joined', newStudent);
}
1.	Listen
2.	Emit
1.	Listen
2.	Emit
Socket.io Client	Code
// add Socket.io client framework
var io = require(’socket.io-client');
// add Socket.io client framework
this.socket = io('http://localhost:3000');
// listen for socket connection from server
this.socket.on(’connect', function() {
var newStudent = {name: nameFromForm, type: “student”};
// emit custom event with data (newStudent) back to server
this.emit('join', newStudent);
}
// listen for custom events with data (payload) “emitted” by server
this.socket.on('joined', function(payload) {
// do stuff with payload...
}
1.	Listen
2.	Emit
Socket.io	Demo
• Socket.io,	Express	/	NodeJS,	React,	D3,	Bootstrap,	Webpack
• Lynda.com:	Building	a	Polling	App	with	Socket	IO	and	React.js
Questions?
Pick	me!
Pick	me!
Pick	me!
Pick	me!
Pick	me!
Pick	me!
Pick	me!
Pick	me!
Key	References
• https://www.lynda.com/Web-Development-tutorials/Building-Polling-
App-Socket-IO-React-js/387145-2.html
• https://socket.io/get-started/chat/
• http://www.jonahnisenson.com/what-are-websockets-and-why-do-i-
need-socket-io/
• https://nodesource.com/blog/understanding-socketio/
• http://enterprisewebbook.com/ch8_websockets.html
• http://blog.teamtreehouse.com/an-introduction-to-websockets
• https://www.pubnub.com/blog/2015-01-05-websockets-vs-rest-api-
understanding-the-difference/

More Related Content

PPTX
Intro to WebSockets
PPTX
Mqtt(Message queue telemetry protocol) presentation
PDF
MQTT - MQ Telemetry Transport for Message Queueing
PPTX
MQTT IOT Protocol Introduction
PDF
An introduction to MQTT
PPTX
Introduction to MQ Telemetry Transport (MQTT)
PPTX
CoAP - Web Protocol for IoT
Intro to WebSockets
Mqtt(Message queue telemetry protocol) presentation
MQTT - MQ Telemetry Transport for Message Queueing
MQTT IOT Protocol Introduction
An introduction to MQTT
Introduction to MQ Telemetry Transport (MQTT)
CoAP - Web Protocol for IoT

What's hot (20)

PDF
HTTP Request and Response Structure
PPTX
PPT
HTTP Basics
PDF
J2EE Introduction
PPTX
REST & RESTful Web Services
PPT
Php Presentation
PPTX
virtual hosting and configuration
PPTX
Front end web development
PPT
Web Standards
PPT
RESTful services
PPTX
OVERVIEW OF FACEBOOK SCALABLE ARCHITECTURE.
PDF
WEB I - 01 - Introduction to Web Development
PPTX
Front-end development introduction (HTML, CSS). Part 1
PPTX
HTTP Request Header and HTTP Status Code
PPTX
Introduction to Web Development
PPTX
Web application framework
PPT
Introduction to the Web API
PPT
Java Servlets
PPT
Introduction to Basic Concepts in Web
PDF
Internet programming lecture 1
HTTP Request and Response Structure
HTTP Basics
J2EE Introduction
REST & RESTful Web Services
Php Presentation
virtual hosting and configuration
Front end web development
Web Standards
RESTful services
OVERVIEW OF FACEBOOK SCALABLE ARCHITECTURE.
WEB I - 01 - Introduction to Web Development
Front-end development introduction (HTML, CSS). Part 1
HTTP Request Header and HTTP Status Code
Introduction to Web Development
Web application framework
Introduction to the Web API
Java Servlets
Introduction to Basic Concepts in Web
Internet programming lecture 1
Ad

Viewers also liked (20)

PPTX
Geometría lineal
PPTX
Edemade reinke
PDF
Materiais e processos gráficos
PDF
How to Become a Thought Leader in Your Niche
PPTX
Lecture Notes, 3 15-17
PDF
Olivia Humphrey Understanding the Marketplace, Part Two
PDF
Feedback-Regeln für eine bessere Kommunikation
PPTX
Fotos antequera
PDF
Cambiar el fregadero de la cocina
PDF
PERDIDAS EN SILOS Y GRANOS
PPTX
Rinitis
PDF
Agile Organisation
PDF
Overview and Implications of the House Republican Bill
PDF
Sprint 56
PPTX
Behaviourist learning theory (in SLA)
PDF
Applying Machine Learning to Live Patient Data
PDF
Programming WebSockets - OSCON 2010
PPTX
vlavrynovych - WebSockets Presentation
PDF
Presentation websockets
PPTX
WebSockets and Equinox OSGi in a Servlet Container - Nedelcho Delchev
Geometría lineal
Edemade reinke
Materiais e processos gráficos
How to Become a Thought Leader in Your Niche
Lecture Notes, 3 15-17
Olivia Humphrey Understanding the Marketplace, Part Two
Feedback-Regeln für eine bessere Kommunikation
Fotos antequera
Cambiar el fregadero de la cocina
PERDIDAS EN SILOS Y GRANOS
Rinitis
Agile Organisation
Overview and Implications of the House Republican Bill
Sprint 56
Behaviourist learning theory (in SLA)
Applying Machine Learning to Live Patient Data
Programming WebSockets - OSCON 2010
vlavrynovych - WebSockets Presentation
Presentation websockets
WebSockets and Equinox OSGi in a Servlet Container - Nedelcho Delchev
Ad

Similar to Introduction to WebSockets Presentation (20)

PPTX
ClientServer Websocket.pptx
PDF
Building Next Generation Real-Time Web Applications using Websockets
PPTX
Basic understanding of websocket and and REST API
ODP
ISM APAC TechTalk - WebSockets Presentation
PPTX
Intro to Web Sockets
KEY
Websockets with ruby
PPTX
Webinar slides "Building Real-Time Collaborative Web Applications"
PPTX
Building real-time-collaborative-web-applications
PPTX
Web Real-time Communications
PPTX
Understand WebSockets
PPTX
Introduction of WebSockets
PPTX
presentation in .net programming web sockets.pptx
PDF
Nuts and Bolts of WebSocket Devoxx 2014
PPTX
WebSockets in JEE 7
PPTX
PDF
IRJET- An Overview of Web Sockets: The Future of Real-Time Communication
PPTX
Web sockets - Pentesting
PPTX
WebSockets-Revolutionizing-Real-Time-Communication.pptx
PDF
Dev con kolkata 2012 websockets
ZIP
Websockets at tossug
ClientServer Websocket.pptx
Building Next Generation Real-Time Web Applications using Websockets
Basic understanding of websocket and and REST API
ISM APAC TechTalk - WebSockets Presentation
Intro to Web Sockets
Websockets with ruby
Webinar slides "Building Real-Time Collaborative Web Applications"
Building real-time-collaborative-web-applications
Web Real-time Communications
Understand WebSockets
Introduction of WebSockets
presentation in .net programming web sockets.pptx
Nuts and Bolts of WebSocket Devoxx 2014
WebSockets in JEE 7
IRJET- An Overview of Web Sockets: The Future of Real-Time Communication
Web sockets - Pentesting
WebSockets-Revolutionizing-Real-Time-Communication.pptx
Dev con kolkata 2012 websockets
Websockets at tossug

Recently uploaded (20)

PDF
Hybrid model detection and classification of lung cancer
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PPT
Geologic Time for studying geology for geologist
PDF
CloudStack 4.21: First Look Webinar slides
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PPTX
Benefits of Physical activity for teenagers.pptx
PPTX
Chapter 5: Probability Theory and Statistics
PDF
August Patch Tuesday
PDF
STKI Israel Market Study 2025 version august
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PPTX
The various Industrial Revolutions .pptx
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
1 - Historical Antecedents, Social Consideration.pdf
Hybrid model detection and classification of lung cancer
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Geologic Time for studying geology for geologist
CloudStack 4.21: First Look Webinar slides
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
WOOl fibre morphology and structure.pdf for textiles
O2C Customer Invoices to Receipt V15A.pptx
Benefits of Physical activity for teenagers.pptx
Chapter 5: Probability Theory and Statistics
August Patch Tuesday
STKI Israel Market Study 2025 version august
Univ-Connecticut-ChatGPT-Presentaion.pdf
A comparative study of natural language inference in Swahili using monolingua...
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
The various Industrial Revolutions .pptx
A review of recent deep learning applications in wood surface defect identifi...
NewMind AI Weekly Chronicles – August ’25 Week III
Final SEM Unit 1 for mit wpu at pune .pptx
1 - Historical Antecedents, Social Consideration.pdf

Introduction to WebSockets Presentation