SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
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/

Weitere ähnliche Inhalte

Was ist angesagt?

Mobile transportlayer
Mobile transportlayerMobile transportlayer
Mobile transportlayer
Rahul Hada
 

Was ist angesagt? (20)

Mobile transportlayer
Mobile transportlayerMobile transportlayer
Mobile transportlayer
 
Web services
Web servicesWeb services
Web services
 
HyperText Transfer Protocol (HTTP)
HyperText Transfer Protocol (HTTP)HyperText Transfer Protocol (HTTP)
HyperText Transfer Protocol (HTTP)
 
HTTP/2 Changes Everything
HTTP/2 Changes EverythingHTTP/2 Changes Everything
HTTP/2 Changes Everything
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
OAuth2 - Introduction
OAuth2 - IntroductionOAuth2 - Introduction
OAuth2 - Introduction
 
web connectivity in IoT
web connectivity in IoTweb connectivity in IoT
web connectivity in IoT
 
REST API
REST APIREST API
REST API
 
gRPC Design and Implementation
gRPC Design and ImplementationgRPC Design and Implementation
gRPC Design and Implementation
 
Soap vs rest
Soap vs restSoap vs rest
Soap vs rest
 
Wireshark
WiresharkWireshark
Wireshark
 
gRPC with java
gRPC with javagRPC with java
gRPC with java
 
Routing ppt
Routing pptRouting ppt
Routing ppt
 
Understanding JWT Exploitation
Understanding JWT ExploitationUnderstanding JWT Exploitation
Understanding JWT Exploitation
 
Json web token
Json web tokenJson web token
Json web token
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 
Http protocol
Http protocolHttp protocol
Http protocol
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
MQTT - MQ Telemetry Transport for Message Queueing
MQTT - MQ Telemetry Transport for Message QueueingMQTT - MQ Telemetry Transport for Message Queueing
MQTT - MQ Telemetry Transport for Message Queueing
 
Ajax Ppt 1
Ajax Ppt 1Ajax Ppt 1
Ajax Ppt 1
 

Andere mochten auch

Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010
sullis
 
vlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets Presentationvlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets Presentation
Volodymyr Lavrynovych
 

Andere mochten auch (20)

Geometría lineal
Geometría linealGeometría lineal
Geometría lineal
 
Edemade reinke
Edemade reinkeEdemade reinke
Edemade reinke
 
Materiais e processos gráficos
Materiais e processos gráficosMateriais e processos gráficos
Materiais e processos gráficos
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 
Lecture Notes, 3 15-17
Lecture Notes, 3 15-17Lecture Notes, 3 15-17
Lecture Notes, 3 15-17
 
Olivia Humphrey Understanding the Marketplace, Part Two
Olivia Humphrey Understanding the Marketplace, Part TwoOlivia Humphrey Understanding the Marketplace, Part Two
Olivia Humphrey Understanding the Marketplace, Part Two
 
Feedback-Regeln für eine bessere Kommunikation
Feedback-Regeln für eine bessere KommunikationFeedback-Regeln für eine bessere Kommunikation
Feedback-Regeln für eine bessere Kommunikation
 
Fotos antequera
Fotos antequeraFotos antequera
Fotos antequera
 
Cambiar el fregadero de la cocina
Cambiar el fregadero de la cocinaCambiar el fregadero de la cocina
Cambiar el fregadero de la cocina
 
PERDIDAS EN SILOS Y GRANOS
PERDIDAS EN SILOS Y GRANOSPERDIDAS EN SILOS Y GRANOS
PERDIDAS EN SILOS Y GRANOS
 
Rinitis
RinitisRinitis
Rinitis
 
Agile Organisation
Agile OrganisationAgile Organisation
Agile Organisation
 
Overview and Implications of the House Republican Bill
Overview and Implications of the House Republican BillOverview and Implications of the House Republican Bill
Overview and Implications of the House Republican Bill
 
A short guide to teach English to kids with the books they have.
A short guide to teach English to kids with the books they have.A short guide to teach English to kids with the books they have.
A short guide to teach English to kids with the books they have.
 
Sprint 56
Sprint 56Sprint 56
Sprint 56
 
Behaviourist learning theory (in SLA)
Behaviourist learning theory (in SLA) Behaviourist learning theory (in SLA)
Behaviourist learning theory (in SLA)
 
Applying Machine Learning to Live Patient Data
Applying Machine Learning to  Live Patient DataApplying Machine Learning to  Live Patient Data
Applying Machine Learning to Live Patient Data
 
Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010
 
vlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets Presentationvlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets Presentation
 
Presentation websockets
Presentation websocketsPresentation websockets
Presentation websockets
 

Ähnlich wie Introduction to WebSockets Presentation

E business internet_basics
E business internet_basicsE business internet_basics
E business internet_basics
Radiant Minds
 
Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...
smitha273566
 
ICS 2203-WEB APPLICATION DEVELOPMENT-EDUC Y2S1_MATHCOMP.docx
ICS 2203-WEB APPLICATION DEVELOPMENT-EDUC Y2S1_MATHCOMP.docxICS 2203-WEB APPLICATION DEVELOPMENT-EDUC Y2S1_MATHCOMP.docx
ICS 2203-WEB APPLICATION DEVELOPMENT-EDUC Y2S1_MATHCOMP.docx
Martin Mulwa
 
How the internet_works
How the internet_worksHow the internet_works
How the internet_works
arun nalam
 

Ähnlich wie Introduction to WebSockets Presentation (20)

E business internet_basics
E business internet_basicsE business internet_basics
E business internet_basics
 
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Html5 web sockets - Brad Drysdale - London Web 2011-10-20Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
 
SignalR With ASP.Net part1
SignalR With ASP.Net part1SignalR With ASP.Net part1
SignalR With ASP.Net part1
 
How the Internet Works
How the Internet WorksHow the Internet Works
How the Internet Works
 
WT_TOTAL.pdf
WT_TOTAL.pdfWT_TOTAL.pdf
WT_TOTAL.pdf
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
 
Javascript - Getting started | DevCom ISITCom
Javascript - Getting started | DevCom ISITComJavascript - Getting started | DevCom ISITCom
Javascript - Getting started | DevCom ISITCom
 
From Data Push to WebSockets
From Data Push to WebSocketsFrom Data Push to WebSockets
From Data Push to WebSockets
 
API Design and WebSocket
API Design and WebSocketAPI Design and WebSocket
API Design and WebSocket
 
CS101- Introduction to Computing- Lecture 30
CS101- Introduction to Computing- Lecture 30CS101- Introduction to Computing- Lecture 30
CS101- Introduction to Computing- Lecture 30
 
Introduction to Network Applications & Network Services
Introduction to  Network Applications &  Network ServicesIntroduction to  Network Applications &  Network Services
Introduction to Network Applications & Network Services
 
Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...
 
ICS 2203-WEB APPLICATION DEVELOPMENT-EDUC Y2S1_MATHCOMP.docx
ICS 2203-WEB APPLICATION DEVELOPMENT-EDUC Y2S1_MATHCOMP.docxICS 2203-WEB APPLICATION DEVELOPMENT-EDUC Y2S1_MATHCOMP.docx
ICS 2203-WEB APPLICATION DEVELOPMENT-EDUC Y2S1_MATHCOMP.docx
 
How the internet_works
How the internet_worksHow the internet_works
How the internet_works
 
HTML CSS web engineering slides topics
HTML CSS web engineering slides topicsHTML CSS web engineering slides topics
HTML CSS web engineering slides topics
 
Web design - How the Web works?
Web design - How the Web works?Web design - How the Web works?
Web design - How the Web works?
 
Intro to internet 1
Intro to internet 1Intro to internet 1
Intro to internet 1
 
Building real time applications with Symfony2
Building real time applications with Symfony2Building real time applications with Symfony2
Building real time applications with Symfony2
 
Howthe internet
Howthe internetHowthe internet
Howthe internet
 
The Web of Things
The Web of ThingsThe Web of Things
The Web of Things
 

Kürzlich hochgeladen

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Introduction to WebSockets Presentation