SlideShare uma empresa Scribd logo
1 de 49
Enhancing Mobile User
Experience with WebSocket
Mauricio “Maltron” Leal
maltron@gmail.com
@maltron
WebSocket 101
(The Short Story)
Web Server
(WebSocket compliant)
Endpoint
Client
(WebSocket compliant)
Endpoint
ws://webserver:80/mycontext/endpoint ?
GET /mycontext/endpoint HTTP/1.1
Host: webserver Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: xqBt3ImNzJbYqRINxEFlkg==
Origin: http://client
Sec-WebSocket-Version: 13
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: K7DJLdLooIwIG/MOpvWFB3y3FE8=
Web Server
(WebSocket compliant)
Endpoint
Client
(WebSocket compliant)
Endpoint
HTTP/1.1 101 Switching Protocols
Web Server
(WebSocket compliant)
Endpoint
Client
(WebSocket compliant)
Endpoint
CONNECTED
A connection is established
and “never” closed
Bi-directional & full duplex connection on a
single TCP socket.
It can be secured using SSLIt can be on average, 700 x
faster than AJAX polling.
Web Server
(WebSocket compliant)
Endpoint
Client
(WebSocket compliant)
Endpoint
Message
Web Server
(WebSocket compliant)
Endpoint
Client
(WebSocket compliant)
Endpoint
Message
Endpoint Endpoint
Endpoint
Endpoint
Endpoint
Message
Endpoint
Message
Browser
(Using HTML 5)
Standalone
(Webscoket Client)
Mobile
(HTML 5 Browser)
Mobile
(WebSocket Client)
WebSocket Advanced
(The Geek Story)
Endpoint Endpoint
javax.websocket
Endpoint
javax.websocket
Endpoint
Endpoints represents an object that can handle
websocket conversations.
1 Instance = 1 Thread = 1 Connection
Endpoint
javax.websocket
Endpoint
For each endpoint class, holds lifecycle methods that
may be overridden to intercept a websocket open, error
and close events.
Lifecycle
Methods
Endpoint
javax.websocket
Endpoint
Programmatic Endpoint
public class MyEndpoint extends Endpoint {
@Override
public void onOpen(Session s,
EndpointConfig c) {
// A connection was established
}
@Override
public void onClose(Session s, CloseReason
reason) {}
@Override
public void onError(Session s, Throwable
thr) {}
Endpoint
javax.websocket
Endpoint
Programmatic Endpoint:
Need to create a Message Handler
public class MyEndpoint extends Endpoint {
...
@Override
public void onOpen(Session s,
EndpointConfig c) {
session.addMessageHandler(
new MessageHandler.Whole<String>()) {
@Override
public void onMessage(String m) {
try {
s.getBasicRemote().sendText(“hi”);
} catch(IOException e) {
// Houston: we‟ve got a problem
}
...
Message Handler
Endpoint
javax.websocket
Endpoint
Annotated Endpoint: Much Simpler
@ServerEndpoint(“/endpoint”)
public class MyEndpoint extends Endpoint {
@OnOpen
public void open(Session s) {}
@OnMessage
public void myMessage(String message) {}
@OnClose
public void close(Session s) {}
No need for a
Message Handler
Endpoint Endpoint
javax.websocket
Session
A Session represents a conversation between two
Endpoints.
It captures both Server and
Client State
Endpoint Endpoint
javax.websocket
Session
For sending a simple message to another Endpoint
try {
session.getBasicRemote().sendText(“Hello World”);
} catch(IOException e) {
// Houston: We‟ve got a problem
}
“Hello World”
Endpoint
Endpoint
javax.websocket
Session
try {
for(Session s: session.getOpenSessions())
s.getBasicRemote().sendText(“Hello All”);
} catch(IOException e) {
// Houston: We‟ve got a problem
}
EndpointFor sending the same message to all open Sessions
Endpoint Endpoint
javax.websocket
Session
Some other Session’s methods very useful
boolean isOpen()
boolean isSecure()
void setMaxIdleTimeout(long time)
void addMessageHandler(MessageHandler handler)
: Check if the connection is open
: Check if the connection is secure
: Max Idle Timeout for Inactivity
: Different Message Handlers
Endpoint
Waiting for Message to be delivered: Blocking
...
session.getBasicRemote().sendText(“Hi everyone”);
...
RemoteEndpoint.Basic getBasicRemote()
Endpoint
Create another Thread in order to send it.
...
session.getAsyncRemote().sendText(“Hi everyone”);
...
RemoteEndpoint.Async getAsyncRemote()
Endpoint
Messages can be in different types
RemoteEndpoint.Basic.sendText(String text)
Text Messages
RemoteEndpoint.Basic.sendBinary(ByteBuffer data)
Binary Messages
RemoteEndpoint.sendPing(ByteByffer data)
Ping Frame
RemoteEndpoint.sendPong(ByteBuffer data)
Pong Frame
Endpoint
@ServerEndpoint(“/response”)
public class Response {
@OnMessage
public void textMessage(String msg, Session s) {
System.out.println(“Text:”+msg);
}
@OnMessage
public void binaryMessage(Session s, ByteBuffer msg) {
System.out.println(“Binary:”+msg.toString());
}
@OnMessage
public void pongMessage(Session s, PongMessage msg) {
System.out.println(“Pong:”+msg.getApplicationData().
toString();
}
}
Receiving Different type of Messages
Endpoint Endpoint
public class Person {
private int ID;
public String name;
public String position;
...
POJO
{
“ID”: 2
“name”: “somebody@gmail.com”
“position”: “Developer”
}
JSON
Encoder
JSON
Encoder
Decouples the business logic from serialization and
deserialization
Endpoint Endpoint
public class Person {
private int ID;
public String name;
public String position;
...
POJO
Decoder
JSON
Decoder
{
“ID”: 2
“name”: “somebody@gmail.com”
“position”: “Developer”
}
JSON
Decouples the business logic from serialization and
deserialization
Endpoint Endpoint
o Access details of the initial HTTP request for a connection
You can provide custom configuration on how the
container creates a server endpoint instances.
o Perform custom checks on the Origin HTTP header
o Modify the WebSocket handshake response
o Choose a WebSocket subprotocol
o Control the instantiation and initialization of endpoint
Endpoint EndpointYou can provide custom configuration on how the
container creates a server endpoint instances.
@Override
public void modifyHandshake(ServerEndpointConfig config,
HandshakeRequest request, HandshakeResponse response) {
config.getUserProperties().put(“handshakereq”, req);
}
WebSocket@Mobile
(Sorry, no Windows Mobile)
Using Mobile’s
Browser
Using Native
Implementation
2 Different approaches for using WebSockets
The Connection is
never reliable
On a Mobile Universe
Using a open
connection for a long
time, can drain your
battery rapidly.
In Native apps, use
ONLY when the app
is on foregroud.
Using Mobile’s
Browser
The Good The Bad
No worries about
deployment:
It’s just a website
Not all Mobile Browsers
support WebSockets
Concern about different
version of browsers.
Must be deal with
JavaScript.
The same code for
every device
The Good The Bad
More easy ways to
support older versions of
iOS and Android.
Can’t reuse the same
code: Need to consider
different
implementations
More work on
maintenance
Using Native
Implementation More Control over a
Connection
6.0
6.1
Safari
iOS
Browser
Android
Mini
Opera
Browser
Blackberry
Android
Chrome
Android
Firefox
7.0
5.0
7.0
source: http://caniuse.com/websockets
4.2
4.3
4.4
7.0
10.0 33.0 26.0
Mobile
Opera
12.1
16.0
Support of WebSocktes in Mobile Browsers
function WebSocketTest(){
if ("WebSocket" in window) {
// WebSocket Connection goes here
alert("WebSockets supported
rnrnBrowser: “);
} else {
// the browser doesn't support
alert("WebSockets NOT supported”);
}}
Testing if a WebSocket is supported in your Browser
(Using JavaScript)
$(document).ready(function() {
if( typeof(WebSocket) != "function" ) {
$('body').html("<h1>Error</h1><p>Your
browser does not support Web Sockets.
</p>");
}});
Essentially, just test if WebSocket is defined
or not
var connection = new WebSocket(
„ws://webserver:80/mycontext/endpoint‟);
connection.onopen = function() {
// connection opened
console.log(„connection open‟);
console.send(„Hello World‟);
}
connection.onmessage = function(message) {
console.log(„Received message from server:‟);
console.log(message);
}
A simple JavaScript code using WebSocket
A tool for helping Monitoring WebSocket Traffic: Chrome
Dev Tools
• Open up the Developer Tools
• Switch to the Network tab
• Click on the entry for your
WebSocket connection
• Switch to the Frames tab.
http://developers.google.com/chrome-developer-tool/
Google’s Chrome Dev Tools
Socket Rocket
https://github.com/square/SocketRocket
Unit WebSocket Client
https://code.google.com/p/unit/wiki/UnittWebSocketClient
iOS WebSocket Client Libraries
Recommended
Autobahn Android
http://autobahn.ws/android
WebSocket and Socket.IO
https://github.com/koush/android-websockets
Android WebSocket Client Libraries
Recommended
jWebSocket
https://jwebsocket.org/
Secure WebSockets
https://github.com/palmerc/SecureWebSockets
WebSocket@Show
Possible Scenarios
Enable “fast” notification for a “fast” reaction
• Real Time Notification: Seconds matter
Both iOS and Android has
Notification Systems.
Multiple devices (including mobile) to be in sync with
other sources
• Transfer several messages to be sure if
a device is in sync
• Exchange of several messages are
extremely fast
Enabling people in sharing and interacting in the same
content at the same time.
• Real Time Video Sharing
• Broader collaboration
Mobile Gaming: Synchronize all clients in a Massive
Multiplayer Gaming
• Synchronization of elements in all
clients, through the Server
• Adding instant notifications
• Instant chat between players
Presenting real time information from several sources.
• Instant information to the user
• Capacity to the user to react more
fast
Reading instant patient information and broadcasting to
his doctor
• Monitor life treaty information
• Broadcast to hospital / doctor
Enabling fast awareness in a large environment
• Awareness of other people in real time
• Keep track of living events
Client B
Client A
Connecting to other hardware (Raspberry Pi), which has
the capability of running WebSocket container.
http://developer.kaazing.com/portfolio/real-time-interactions-with-physical-objects-over-the-web/
• Using WebSockets as the default way to
connected to other hardware devices.
• Leveraging you WebSockets know-
how.
WebSocket@DevNation
Real-time collaborative writing:
When WebSocket met Ascii Doctor
4:50 pm
Room: 208
Maxime Gréau
Thank you
Special Thanks: Neto Marin <neto.marin at gmail.com>
maltron@gmail.com
Avaliable on Slideshare.net
http://www.slideshare.net/maltron/enhancing-mobile-user-experience-with-websocket

Mais conteúdo relacionado

Mais procurados

Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and...
Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and...Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and...
Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and...Amitesh Madhur
 
Going Live! with Comet
Going Live! with CometGoing Live! with Comet
Going Live! with CometSimon Willison
 
HTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the WebHTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the WebPeter Lubbers
 
Asynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and JavaAsynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and JavaJames Falkner
 
Building WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using AtmosphereBuilding WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using Atmospherejfarcand
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serializationGWTcon
 
WEB SOCKET 應用
WEB SOCKET 應用WEB SOCKET 應用
WEB SOCKET 應用Jerromy Lee
 
Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!jfarcand
 
Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3Alex Kavanagh
 
Setup ephemeral password for TURN, Learn RTC in less than 200 Lines of code
Setup ephemeral password for TURN, Learn RTC in less than 200 Lines of codeSetup ephemeral password for TURN, Learn RTC in less than 200 Lines of code
Setup ephemeral password for TURN, Learn RTC in less than 200 Lines of codeAmitesh Madhur
 
The Atmosphere Framework
The Atmosphere FrameworkThe Atmosphere Framework
The Atmosphere Frameworkjfarcand
 
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and ScalaWriting highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and Scalajfarcand
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...Tom Croucher
 
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 RedisYork Tsai
 

Mais procurados (20)

Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and...
Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and...Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and...
Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and...
 
Going Live! with Comet
Going Live! with CometGoing Live! with Comet
Going Live! with Comet
 
HTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the WebHTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the Web
 
Time for Comet?
Time for Comet?Time for Comet?
Time for Comet?
 
Asynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and JavaAsynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and Java
 
Building WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using AtmosphereBuilding WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using Atmosphere
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
 
WEB SOCKET 應用
WEB SOCKET 應用WEB SOCKET 應用
WEB SOCKET 應用
 
WebSockets in JEE 7
WebSockets in JEE 7WebSockets in JEE 7
WebSockets in JEE 7
 
Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!
 
Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3
 
Setup ephemeral password for TURN, Learn RTC in less than 200 Lines of code
Setup ephemeral password for TURN, Learn RTC in less than 200 Lines of codeSetup ephemeral password for TURN, Learn RTC in less than 200 Lines of code
Setup ephemeral password for TURN, Learn RTC in less than 200 Lines of code
 
The Atmosphere Framework
The Atmosphere FrameworkThe Atmosphere Framework
The Atmosphere Framework
 
Intro to WebSockets
Intro to WebSocketsIntro to WebSockets
Intro to WebSockets
 
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and ScalaWriting highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
 
WebRTC for Managers!
WebRTC for Managers!WebRTC for Managers!
WebRTC for Managers!
 
Nodejs.meetup
Nodejs.meetupNodejs.meetup
Nodejs.meetup
 
Measuring Continuity
Measuring ContinuityMeasuring Continuity
Measuring Continuity
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
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
 

Semelhante a Enhancing Mobile User Experience with WebSocket

vlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets Presentationvlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets PresentationVolodymyr Lavrynovych
 
Jwebsocketmobiletechcon2010en 100912071225 Phpapp01
Jwebsocketmobiletechcon2010en 100912071225 Phpapp01Jwebsocketmobiletechcon2010en 100912071225 Phpapp01
Jwebsocketmobiletechcon2010en 100912071225 Phpapp01purans
 
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 DevelopersViktor Gamov
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web SocketsFahad Golra
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websocketsWim Godden
 
V2 peter-lubbers-sf-jug-websocket
V2 peter-lubbers-sf-jug-websocketV2 peter-lubbers-sf-jug-websocket
V2 peter-lubbers-sf-jug-websocketbrent bucci
 
Dev con kolkata 2012 websockets
Dev con kolkata 2012   websocketsDev con kolkata 2012   websockets
Dev con kolkata 2012 websocketsSANKARSAN BOSE
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)Ericom Software
 
WebSockets Jump Start
WebSockets Jump StartWebSockets Jump Start
WebSockets Jump StartHaim Michael
 
KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享Chia Wei Tsai
 
Unity and WebSockets
Unity and WebSocketsUnity and WebSockets
Unity and WebSocketsJosh Glover
 
Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax Wrajivmordani
 
Real-Time with Flowdock
Real-Time with FlowdockReal-Time with Flowdock
Real-Time with FlowdockFlowdock
 

Semelhante a Enhancing Mobile User Experience with WebSocket (20)

vlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets Presentationvlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets Presentation
 
Jwebsocketmobiletechcon2010en 100912071225 Phpapp01
Jwebsocketmobiletechcon2010en 100912071225 Phpapp01Jwebsocketmobiletechcon2010en 100912071225 Phpapp01
Jwebsocketmobiletechcon2010en 100912071225 Phpapp01
 
jWebSocket MobileTechCon 2010 - WebSockets on Android, Symbian and BlackBerry
jWebSocket MobileTechCon 2010 - WebSockets on Android, Symbian and BlackBerryjWebSocket MobileTechCon 2010 - WebSockets on Android, Symbian and BlackBerry
jWebSocket MobileTechCon 2010 - WebSockets on Android, Symbian and BlackBerry
 
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
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web Sockets
 
ServerSentEventsV2.pdf
ServerSentEventsV2.pdfServerSentEventsV2.pdf
ServerSentEventsV2.pdf
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
 
V2 peter-lubbers-sf-jug-websocket
V2 peter-lubbers-sf-jug-websocketV2 peter-lubbers-sf-jug-websocket
V2 peter-lubbers-sf-jug-websocket
 
5.node js
5.node js5.node js
5.node js
 
Dev con kolkata 2012 websockets
Dev con kolkata 2012   websocketsDev con kolkata 2012   websockets
Dev con kolkata 2012 websockets
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
 
WebSockets Jump Start
WebSockets Jump StartWebSockets Jump Start
WebSockets Jump Start
 
KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享
 
Html5 websockets
Html5 websocketsHtml5 websockets
Html5 websockets
 
Unity and WebSockets
Unity and WebSocketsUnity and WebSockets
Unity and WebSockets
 
Websocket
WebsocketWebsocket
Websocket
 
Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax W
 
Socket.io
Socket.ioSocket.io
Socket.io
 
Real-Time with Flowdock
Real-Time with FlowdockReal-Time with Flowdock
Real-Time with Flowdock
 

Último

Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirtrahman018755
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsThierry TROUIN ☁
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Roomdivyansh0kumar0
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Roomdivyansh0kumar0
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 

Último (20)

Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with Flows
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girls
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 

Enhancing Mobile User Experience with WebSocket

  • 1.
  • 2. Enhancing Mobile User Experience with WebSocket Mauricio “Maltron” Leal maltron@gmail.com @maltron
  • 4. Web Server (WebSocket compliant) Endpoint Client (WebSocket compliant) Endpoint ws://webserver:80/mycontext/endpoint ? GET /mycontext/endpoint HTTP/1.1 Host: webserver Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: xqBt3ImNzJbYqRINxEFlkg== Origin: http://client Sec-WebSocket-Version: 13
  • 5. HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: K7DJLdLooIwIG/MOpvWFB3y3FE8= Web Server (WebSocket compliant) Endpoint Client (WebSocket compliant) Endpoint HTTP/1.1 101 Switching Protocols
  • 6. Web Server (WebSocket compliant) Endpoint Client (WebSocket compliant) Endpoint CONNECTED A connection is established and “never” closed Bi-directional & full duplex connection on a single TCP socket. It can be secured using SSLIt can be on average, 700 x faster than AJAX polling.
  • 10. Endpoint Message Browser (Using HTML 5) Standalone (Webscoket Client) Mobile (HTML 5 Browser) Mobile (WebSocket Client)
  • 12. Endpoint Endpoint javax.websocket Endpoint javax.websocket Endpoint Endpoints represents an object that can handle websocket conversations. 1 Instance = 1 Thread = 1 Connection
  • 13. Endpoint javax.websocket Endpoint For each endpoint class, holds lifecycle methods that may be overridden to intercept a websocket open, error and close events. Lifecycle Methods
  • 14. Endpoint javax.websocket Endpoint Programmatic Endpoint public class MyEndpoint extends Endpoint { @Override public void onOpen(Session s, EndpointConfig c) { // A connection was established } @Override public void onClose(Session s, CloseReason reason) {} @Override public void onError(Session s, Throwable thr) {}
  • 15. Endpoint javax.websocket Endpoint Programmatic Endpoint: Need to create a Message Handler public class MyEndpoint extends Endpoint { ... @Override public void onOpen(Session s, EndpointConfig c) { session.addMessageHandler( new MessageHandler.Whole<String>()) { @Override public void onMessage(String m) { try { s.getBasicRemote().sendText(“hi”); } catch(IOException e) { // Houston: we‟ve got a problem } ... Message Handler
  • 16. Endpoint javax.websocket Endpoint Annotated Endpoint: Much Simpler @ServerEndpoint(“/endpoint”) public class MyEndpoint extends Endpoint { @OnOpen public void open(Session s) {} @OnMessage public void myMessage(String message) {} @OnClose public void close(Session s) {} No need for a Message Handler
  • 17. Endpoint Endpoint javax.websocket Session A Session represents a conversation between two Endpoints. It captures both Server and Client State
  • 18. Endpoint Endpoint javax.websocket Session For sending a simple message to another Endpoint try { session.getBasicRemote().sendText(“Hello World”); } catch(IOException e) { // Houston: We‟ve got a problem } “Hello World”
  • 19. Endpoint Endpoint javax.websocket Session try { for(Session s: session.getOpenSessions()) s.getBasicRemote().sendText(“Hello All”); } catch(IOException e) { // Houston: We‟ve got a problem } EndpointFor sending the same message to all open Sessions
  • 20. Endpoint Endpoint javax.websocket Session Some other Session’s methods very useful boolean isOpen() boolean isSecure() void setMaxIdleTimeout(long time) void addMessageHandler(MessageHandler handler) : Check if the connection is open : Check if the connection is secure : Max Idle Timeout for Inactivity : Different Message Handlers
  • 21. Endpoint Waiting for Message to be delivered: Blocking ... session.getBasicRemote().sendText(“Hi everyone”); ... RemoteEndpoint.Basic getBasicRemote()
  • 22. Endpoint Create another Thread in order to send it. ... session.getAsyncRemote().sendText(“Hi everyone”); ... RemoteEndpoint.Async getAsyncRemote()
  • 23. Endpoint Messages can be in different types RemoteEndpoint.Basic.sendText(String text) Text Messages RemoteEndpoint.Basic.sendBinary(ByteBuffer data) Binary Messages RemoteEndpoint.sendPing(ByteByffer data) Ping Frame RemoteEndpoint.sendPong(ByteBuffer data) Pong Frame
  • 24. Endpoint @ServerEndpoint(“/response”) public class Response { @OnMessage public void textMessage(String msg, Session s) { System.out.println(“Text:”+msg); } @OnMessage public void binaryMessage(Session s, ByteBuffer msg) { System.out.println(“Binary:”+msg.toString()); } @OnMessage public void pongMessage(Session s, PongMessage msg) { System.out.println(“Pong:”+msg.getApplicationData(). toString(); } } Receiving Different type of Messages
  • 25. Endpoint Endpoint public class Person { private int ID; public String name; public String position; ... POJO { “ID”: 2 “name”: “somebody@gmail.com” “position”: “Developer” } JSON Encoder JSON Encoder Decouples the business logic from serialization and deserialization
  • 26. Endpoint Endpoint public class Person { private int ID; public String name; public String position; ... POJO Decoder JSON Decoder { “ID”: 2 “name”: “somebody@gmail.com” “position”: “Developer” } JSON Decouples the business logic from serialization and deserialization
  • 27. Endpoint Endpoint o Access details of the initial HTTP request for a connection You can provide custom configuration on how the container creates a server endpoint instances. o Perform custom checks on the Origin HTTP header o Modify the WebSocket handshake response o Choose a WebSocket subprotocol o Control the instantiation and initialization of endpoint
  • 28. Endpoint EndpointYou can provide custom configuration on how the container creates a server endpoint instances. @Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { config.getUserProperties().put(“handshakereq”, req); }
  • 30. Using Mobile’s Browser Using Native Implementation 2 Different approaches for using WebSockets The Connection is never reliable On a Mobile Universe Using a open connection for a long time, can drain your battery rapidly. In Native apps, use ONLY when the app is on foregroud.
  • 31. Using Mobile’s Browser The Good The Bad No worries about deployment: It’s just a website Not all Mobile Browsers support WebSockets Concern about different version of browsers. Must be deal with JavaScript. The same code for every device
  • 32. The Good The Bad More easy ways to support older versions of iOS and Android. Can’t reuse the same code: Need to consider different implementations More work on maintenance Using Native Implementation More Control over a Connection
  • 34. function WebSocketTest(){ if ("WebSocket" in window) { // WebSocket Connection goes here alert("WebSockets supported rnrnBrowser: “); } else { // the browser doesn't support alert("WebSockets NOT supported”); }} Testing if a WebSocket is supported in your Browser (Using JavaScript) $(document).ready(function() { if( typeof(WebSocket) != "function" ) { $('body').html("<h1>Error</h1><p>Your browser does not support Web Sockets. </p>"); }}); Essentially, just test if WebSocket is defined or not
  • 35. var connection = new WebSocket( „ws://webserver:80/mycontext/endpoint‟); connection.onopen = function() { // connection opened console.log(„connection open‟); console.send(„Hello World‟); } connection.onmessage = function(message) { console.log(„Received message from server:‟); console.log(message); } A simple JavaScript code using WebSocket
  • 36. A tool for helping Monitoring WebSocket Traffic: Chrome Dev Tools • Open up the Developer Tools • Switch to the Network tab • Click on the entry for your WebSocket connection • Switch to the Frames tab. http://developers.google.com/chrome-developer-tool/ Google’s Chrome Dev Tools
  • 37. Socket Rocket https://github.com/square/SocketRocket Unit WebSocket Client https://code.google.com/p/unit/wiki/UnittWebSocketClient iOS WebSocket Client Libraries Recommended
  • 38. Autobahn Android http://autobahn.ws/android WebSocket and Socket.IO https://github.com/koush/android-websockets Android WebSocket Client Libraries Recommended jWebSocket https://jwebsocket.org/ Secure WebSockets https://github.com/palmerc/SecureWebSockets
  • 40. Enable “fast” notification for a “fast” reaction • Real Time Notification: Seconds matter Both iOS and Android has Notification Systems.
  • 41. Multiple devices (including mobile) to be in sync with other sources • Transfer several messages to be sure if a device is in sync • Exchange of several messages are extremely fast
  • 42. Enabling people in sharing and interacting in the same content at the same time. • Real Time Video Sharing • Broader collaboration
  • 43. Mobile Gaming: Synchronize all clients in a Massive Multiplayer Gaming • Synchronization of elements in all clients, through the Server • Adding instant notifications • Instant chat between players
  • 44. Presenting real time information from several sources. • Instant information to the user • Capacity to the user to react more fast
  • 45. Reading instant patient information and broadcasting to his doctor • Monitor life treaty information • Broadcast to hospital / doctor
  • 46. Enabling fast awareness in a large environment • Awareness of other people in real time • Keep track of living events Client B Client A
  • 47. Connecting to other hardware (Raspberry Pi), which has the capability of running WebSocket container. http://developer.kaazing.com/portfolio/real-time-interactions-with-physical-objects-over-the-web/ • Using WebSockets as the default way to connected to other hardware devices. • Leveraging you WebSockets know- how.
  • 48. WebSocket@DevNation Real-time collaborative writing: When WebSocket met Ascii Doctor 4:50 pm Room: 208 Maxime Gréau
  • 49. Thank you Special Thanks: Neto Marin <neto.marin at gmail.com> maltron@gmail.com Avaliable on Slideshare.net http://www.slideshare.net/maltron/enhancing-mobile-user-experience-with-websocket