SlideShare a Scribd company logo
1 of 25
Download to read offline
SOCKET.IO – ALTERNATIVE WAYS
FOR REAL-TIME APPLICATION
CREATED BY VORAKAMOL C.
WHAT IS SOCKET.IO ?
CREATED BY VORAKAMOL C.
NOOOOOO!
CREATED BY VORAKAMOL C.
SOCKET.IO - NODE.JS MODULE
FOR REAL-TIME EXCHANGE DATA
BETWEEN SERVER AND CLIENT
CREATED BY VORAKAMOL C.
IMAGINE OF TRADITIONAL POLLING…
CREATED BY VORAKAMOL C.
TRADITIONAL POLLING
Client Server
Request
Response
Request
Response
Next 30 second…
.
.
.
Request
Response
Next 30 second…
CREATED BY VORAKAMOL C.
CLIENT PERIODICALLY SENT REQUEST
TO CHECK WITH SERVER
EVEN THOUGH THERE IS NOTHING
CHANGE IN DATA
CREATED BY VORAKAMOL C.
SERVER HAS TO HANDLE A LOT OF
UNNECESSARY REQUEST
CREATED BY VORAKAMOL C.
NOW, TAKE A BRIEFLY
LOOK INTO SOCKET.IO
CREATED BY VORAKAMOL C.
1. REAL-TIME EXCHANGE DATA
BETWEEN SERVER AND CLIENT
CREATED BY VORAKAMOL C.
2. VARIOUS TRANSPORTATION METHOD
WebSocket
Flash Socket
HTMLFILE
XHR Polling
JSONP Polling
Fallback method
CREATED BY VORAKAMOL C.
3. PURELY WRITTEN IN JAVASCRIPT
ON CLIENT-SIDE WHICH RUN IN THE
BROWSER AND SERVER-SIDE
CREATED BY VORAKAMOL C.
4. CROSS BROWSER AND PLATFORM
Support a lot of browser on both PC and
Mobile
3rd Party Open Source implemented for
Android, iOS, etc…
CREATED BY VORAKAMOL C.
GET STARTED WITH
SOCKET.IO
CREATED BY VORAKAMOL C.
1. SETTING UP ENVIRONMENT
ON SERVER-SIDE
Installing Socket.io, express module in target folder
npm install socket.io express
CREATED BY VORAKAMOL C.
SENDER
RECEIVER
emit("test", {v1: "abc", v2:"def"});
signaling data
socket.on("test", function(data){
console.log("Received data is " + data);
});
BASIC UNDERSTANDING
CREATED BY VORAKAMOL C.
2. CODING ON SERVER-SIDE
var socket = require('socket.io');
var express = require('express');
var http = require('http');
var app = express();
var server = http.createServer(app);
var io = socket.listen( server );
io.sockets.on('connection', function(socket){
socket.on('user_login', function(data){
console.log(data.username + " enters the system!");
io.sockets.socket(socket.id).emit('login_success');
});
});
server.listen(8080);
app.js
When
received a
signal called
“user_login”,
execute
statement
inside
CREATED BY VORAKAMOL C.
3. CODING ON CLIENT-SIDE
<html>
<head>
<script src="scripts/socket.io/node_modules/socket.io-client/dist/socket.io.js"></script>
<script src="scripts/jquery-1.11.0.min.js"></script>
<script>
$(function(){
var socket = io.connect( 'http://10.170.23.18:8080' );
socket.on('connect', function(data){
socket.on('login_success', function(){
$('#login_area').html("Login Success!");
});
});
$('#login_btn').click(function(){
socket.emit('user_login', {username: $('#login_textbox').val()});
});
});
</script>
</head>
index.php
CREATED BY VORAKAMOL C.
3. CODING ON CLIENT-SIDE
<body>
<div id="login_area">
Enter name: <input type="text" id="login_textbox" />
<button type="button" id="login_btn">Login!</button>
</div>
</body>
</html>
index.php
CREATED BY VORAKAMOL C.
4. LET’S SEE THE OUTPUT
STARTING SERVER
CREATED BY VORAKAMOL C.
4. LET’S SEE THE OUTPUT
OPENING WEBSITE
CONNECTION HAS
BEEN ESTABLISHED
TO SERVER
CREATED BY VORAKAMOL C.
4. LET’S SEE THE OUTPUT
TYPING THE NAME
AND CLICK LOGIN
BUTTON
CLIENT WILL EMIT THE SIGNAL CALLED “user_login” ALONG WITH ARGUMENT
CALLED “username” TO THE SERVER
CREATED BY VORAKAMOL C.
4. LET’S SEE THE OUTPUT
SERVER RECEIVED THE SIGNAL CALLED “user_login” ALONG WITH
USERNAME. NEXT, THE SERVER WILL SHOW THE NAME OF THE USER
WHO LOG INTO THE SYSTEM AND EMIT THE SIGNAL CALLED
“login_success” BACK TO THAT CLIENT IN ORDER TO TELL THE CLIENT
THAT LOGIN PROCESS IS SUCCESS
CREATED BY VORAKAMOL C.
4. LET’S SEE THE OUTPUT
WHEN THE CLIENT RECEIVED THE SIGNAL CALLED “login_success”,
THE MESSAGE “Login Success!” WILL SHOW UP ON THE SCREEN
CREATED BY VORAKAMOL C.
REFERENCES
• http://socket.io/
• https://github.com/LearnBoost/Socket.IO/wiki/Configuring-
Socket.IO
• http://java.dzone.com/articles/getting-started-socketio-and
• http://www.sitepoint.com/chat-application-using-socket-io/
• http://code.tutsplus.com/tutorials/real-time-chat-with-nodejs-
socketio-and-expressjs--net-31708
• http://tamas.io/advanced-chat-using-node-js-and-socket-io-
episode-1/
• http://en.wikipedia.org/wiki/Socket.IO
CREATED BY VORAKAMOL C.

More Related Content

What's hot

SockJS Intro
SockJS IntroSockJS Intro
SockJS Intro
Ngoc Dao
 

What's hot (20)

Node worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioNode worshop Realtime - Socket.io
Node worshop Realtime - Socket.io
 
Socket.IO
Socket.IOSocket.IO
Socket.IO
 
WebRTC + Socket.io: building a skype-like video chat with native javascript
WebRTC + Socket.io: building a skype-like video chat with native javascriptWebRTC + Socket.io: building a skype-like video chat with native javascript
WebRTC + Socket.io: building a skype-like video chat with native javascript
 
What is RTCMultiConnection?
What is RTCMultiConnection?What is RTCMultiConnection?
What is RTCMultiConnection?
 
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014
 
Vert.x clustering on Docker, CoreOS and ETCD
Vert.x clustering on Docker, CoreOS and ETCDVert.x clustering on Docker, CoreOS and ETCD
Vert.x clustering on Docker, CoreOS and ETCD
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJS
 
Web3j 2.0 Update
Web3j 2.0 UpdateWeb3j 2.0 Update
Web3j 2.0 Update
 
Dancing with websocket
Dancing with websocketDancing with websocket
Dancing with websocket
 
aiohttp intro
aiohttp introaiohttp intro
aiohttp intro
 
What Is Async, How Does It Work, And When Should I Use It?
What Is Async, How Does It Work, And When Should I Use It?What Is Async, How Does It Work, And When Should I Use It?
What Is Async, How Does It Work, And When Should I Use It?
 
How to send gzipped requests with boto3
How to send gzipped requests with boto3How to send gzipped requests with boto3
How to send gzipped requests with boto3
 
LvivPy4 - Threading vs asyncio
LvivPy4 - Threading vs asyncioLvivPy4 - Threading vs asyncio
LvivPy4 - Threading vs asyncio
 
Introduction to Reactive with Play and Akka - Markus Jura
Introduction to Reactive with Play and Akka - Markus JuraIntroduction to Reactive with Play and Akka - Markus Jura
Introduction to Reactive with Play and Akka - Markus Jura
 
Service Discovery for Continuous Delivery with Docker
Service Discovery for Continuous Delivery with DockerService Discovery for Continuous Delivery with Docker
Service Discovery for Continuous Delivery with Docker
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS Intro
 
NestJS
NestJSNestJS
NestJS
 
HTTPBuilder NG: Back From The Dead
HTTPBuilder NG: Back From The DeadHTTPBuilder NG: Back From The Dead
HTTPBuilder NG: Back From The Dead
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 

Viewers also liked

Building your First MEAN App
Building your First MEAN AppBuilding your First MEAN App
Building your First MEAN App
MongoDB
 
Building notification system in NodeJS + Redis
Building notification system in NodeJS + RedisBuilding notification system in NodeJS + Redis
Building notification system in NodeJS + Redis
Le Duc
 
Real-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and RedisReal-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and Redis
York Tsai
 

Viewers also liked (20)

Realtime web applications with ExpressJS and SocketIO
Realtime web applications with ExpressJS and SocketIORealtime web applications with ExpressJS and SocketIO
Realtime web applications with ExpressJS and SocketIO
 
Node js oc meetup 2 socket io intro
Node js oc meetup 2 socket io introNode js oc meetup 2 socket io intro
Node js oc meetup 2 socket io intro
 
Socket io - JSZurich
Socket io - JSZurichSocket io - JSZurich
Socket io - JSZurich
 
Better d3 charts with tdd
Better d3 charts with tddBetter d3 charts with tdd
Better d3 charts with tdd
 
Data visualization
Data visualizationData visualization
Data visualization
 
tea
teatea
tea
 
Transforming WebSockets
Transforming WebSocketsTransforming WebSockets
Transforming WebSockets
 
Building your First MEAN App
Building your First MEAN AppBuilding your First MEAN App
Building your First MEAN App
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONFun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
Building notification system in NodeJS + Redis
Building notification system in NodeJS + RedisBuilding notification system in NodeJS + Redis
Building notification system in NodeJS + Redis
 
Scalability 09262012
Scalability 09262012Scalability 09262012
Scalability 09262012
 
SQL to NoSQL: Top 6 Questions
SQL to NoSQL: Top 6 QuestionsSQL to NoSQL: Top 6 Questions
SQL to NoSQL: Top 6 Questions
 
Birmingham Meetup
Birmingham MeetupBirmingham Meetup
Birmingham Meetup
 
Mobile App Development With IBM Cloudant
Mobile App Development With IBM CloudantMobile App Development With IBM Cloudant
Mobile App Development With IBM Cloudant
 
Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix
Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM BluemixOffline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix
Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix
 
I See NoSQL Document Stores in Geospatial Applications
I See NoSQL Document Stores in Geospatial ApplicationsI See NoSQL Document Stores in Geospatial Applications
I See NoSQL Document Stores in Geospatial Applications
 
Practical Use of a NoSQL
Practical Use of a NoSQLPractical Use of a NoSQL
Practical Use of a NoSQL
 
Real-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and RedisReal-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and Redis
 

Similar to Socket.IO - Alternative Ways for Real-time Application

java and javascript api dev guide
java and javascript api dev guidejava and javascript api dev guide
java and javascript api dev guide
Zenita Smythe
 
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
Viktor Gamov
 
SocketIOSetupWithAngularJSAppByShubham
SocketIOSetupWithAngularJSAppByShubhamSocketIOSetupWithAngularJSAppByShubham
SocketIOSetupWithAngularJSAppByShubham
Shubham Verma
 
Monitoring and analytics with was liberty
Monitoring and analytics with was libertyMonitoring and analytics with was liberty
Monitoring and analytics with was liberty
sflynn073
 
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaroundGet Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
DataGeekery
 
Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax W
rajivmordani
 

Similar to Socket.IO - Alternative Ways for Real-time Application (20)

Integrating Force.com with Heroku
Integrating Force.com with HerokuIntegrating Force.com with Heroku
Integrating Force.com with Heroku
 
How To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native AppHow To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native App
 
Power ai image-pipeline
Power ai image-pipelinePower ai image-pipeline
Power ai image-pipeline
 
java and javascript api dev guide
java and javascript api dev guidejava and javascript api dev guide
java and javascript api dev guide
 
Security in NodeJS applications
Security in NodeJS applicationsSecurity in NodeJS applications
Security in NodeJS applications
 
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
 
socket.io on SmartFx
socket.io on SmartFxsocket.io on SmartFx
socket.io on SmartFx
 
Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...
Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...
Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...
 
State management
State managementState management
State management
 
SocketIOSetupWithAngularJSAppByShubham
SocketIOSetupWithAngularJSAppByShubhamSocketIOSetupWithAngularJSAppByShubham
SocketIOSetupWithAngularJSAppByShubham
 
Payments On Rails
Payments On RailsPayments On Rails
Payments On Rails
 
Monitoring and analytics with was liberty
Monitoring and analytics with was libertyMonitoring and analytics with was liberty
Monitoring and analytics with was liberty
 
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaroundGet Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
 
Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax W
 
Building Your First App with MongoDB Stitch
Building Your First App with MongoDB StitchBuilding Your First App with MongoDB Stitch
Building Your First App with MongoDB Stitch
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS Application
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
LarKC Tutorial at ISWC 2009 - Second Hands-on Scenario
LarKC Tutorial at ISWC 2009 - Second Hands-on ScenarioLarKC Tutorial at ISWC 2009 - Second Hands-on Scenario
LarKC Tutorial at ISWC 2009 - Second Hands-on Scenario
 
Applications: A Series of States
Applications: A Series of StatesApplications: A Series of States
Applications: A Series of States
 
clara-rules
clara-rulesclara-rules
clara-rules
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Socket.IO - Alternative Ways for Real-time Application

  • 1. SOCKET.IO – ALTERNATIVE WAYS FOR REAL-TIME APPLICATION CREATED BY VORAKAMOL C.
  • 2. WHAT IS SOCKET.IO ? CREATED BY VORAKAMOL C.
  • 4. SOCKET.IO - NODE.JS MODULE FOR REAL-TIME EXCHANGE DATA BETWEEN SERVER AND CLIENT CREATED BY VORAKAMOL C.
  • 5. IMAGINE OF TRADITIONAL POLLING… CREATED BY VORAKAMOL C.
  • 6. TRADITIONAL POLLING Client Server Request Response Request Response Next 30 second… . . . Request Response Next 30 second… CREATED BY VORAKAMOL C.
  • 7. CLIENT PERIODICALLY SENT REQUEST TO CHECK WITH SERVER EVEN THOUGH THERE IS NOTHING CHANGE IN DATA CREATED BY VORAKAMOL C.
  • 8. SERVER HAS TO HANDLE A LOT OF UNNECESSARY REQUEST CREATED BY VORAKAMOL C.
  • 9. NOW, TAKE A BRIEFLY LOOK INTO SOCKET.IO CREATED BY VORAKAMOL C.
  • 10. 1. REAL-TIME EXCHANGE DATA BETWEEN SERVER AND CLIENT CREATED BY VORAKAMOL C.
  • 11. 2. VARIOUS TRANSPORTATION METHOD WebSocket Flash Socket HTMLFILE XHR Polling JSONP Polling Fallback method CREATED BY VORAKAMOL C.
  • 12. 3. PURELY WRITTEN IN JAVASCRIPT ON CLIENT-SIDE WHICH RUN IN THE BROWSER AND SERVER-SIDE CREATED BY VORAKAMOL C.
  • 13. 4. CROSS BROWSER AND PLATFORM Support a lot of browser on both PC and Mobile 3rd Party Open Source implemented for Android, iOS, etc… CREATED BY VORAKAMOL C.
  • 15. 1. SETTING UP ENVIRONMENT ON SERVER-SIDE Installing Socket.io, express module in target folder npm install socket.io express CREATED BY VORAKAMOL C.
  • 16. SENDER RECEIVER emit("test", {v1: "abc", v2:"def"}); signaling data socket.on("test", function(data){ console.log("Received data is " + data); }); BASIC UNDERSTANDING CREATED BY VORAKAMOL C.
  • 17. 2. CODING ON SERVER-SIDE var socket = require('socket.io'); var express = require('express'); var http = require('http'); var app = express(); var server = http.createServer(app); var io = socket.listen( server ); io.sockets.on('connection', function(socket){ socket.on('user_login', function(data){ console.log(data.username + " enters the system!"); io.sockets.socket(socket.id).emit('login_success'); }); }); server.listen(8080); app.js When received a signal called “user_login”, execute statement inside CREATED BY VORAKAMOL C.
  • 18. 3. CODING ON CLIENT-SIDE <html> <head> <script src="scripts/socket.io/node_modules/socket.io-client/dist/socket.io.js"></script> <script src="scripts/jquery-1.11.0.min.js"></script> <script> $(function(){ var socket = io.connect( 'http://10.170.23.18:8080' ); socket.on('connect', function(data){ socket.on('login_success', function(){ $('#login_area').html("Login Success!"); }); }); $('#login_btn').click(function(){ socket.emit('user_login', {username: $('#login_textbox').val()}); }); }); </script> </head> index.php CREATED BY VORAKAMOL C.
  • 19. 3. CODING ON CLIENT-SIDE <body> <div id="login_area"> Enter name: <input type="text" id="login_textbox" /> <button type="button" id="login_btn">Login!</button> </div> </body> </html> index.php CREATED BY VORAKAMOL C.
  • 20. 4. LET’S SEE THE OUTPUT STARTING SERVER CREATED BY VORAKAMOL C.
  • 21. 4. LET’S SEE THE OUTPUT OPENING WEBSITE CONNECTION HAS BEEN ESTABLISHED TO SERVER CREATED BY VORAKAMOL C.
  • 22. 4. LET’S SEE THE OUTPUT TYPING THE NAME AND CLICK LOGIN BUTTON CLIENT WILL EMIT THE SIGNAL CALLED “user_login” ALONG WITH ARGUMENT CALLED “username” TO THE SERVER CREATED BY VORAKAMOL C.
  • 23. 4. LET’S SEE THE OUTPUT SERVER RECEIVED THE SIGNAL CALLED “user_login” ALONG WITH USERNAME. NEXT, THE SERVER WILL SHOW THE NAME OF THE USER WHO LOG INTO THE SYSTEM AND EMIT THE SIGNAL CALLED “login_success” BACK TO THAT CLIENT IN ORDER TO TELL THE CLIENT THAT LOGIN PROCESS IS SUCCESS CREATED BY VORAKAMOL C.
  • 24. 4. LET’S SEE THE OUTPUT WHEN THE CLIENT RECEIVED THE SIGNAL CALLED “login_success”, THE MESSAGE “Login Success!” WILL SHOW UP ON THE SCREEN CREATED BY VORAKAMOL C.
  • 25. REFERENCES • http://socket.io/ • https://github.com/LearnBoost/Socket.IO/wiki/Configuring- Socket.IO • http://java.dzone.com/articles/getting-started-socketio-and • http://www.sitepoint.com/chat-application-using-socket-io/ • http://code.tutsplus.com/tutorials/real-time-chat-with-nodejs- socketio-and-expressjs--net-31708 • http://tamas.io/advanced-chat-using-node-js-and-socket-io- episode-1/ • http://en.wikipedia.org/wiki/Socket.IO CREATED BY VORAKAMOL C.