Text
{
"data": [
{
"restaurant_id": "5",
"name":"El Farolito",
"phone":"415 580 1405",
"email":"el.farolito@gmail.com",
"floorplan":"fasdfasdfasdfasdfasdfasdfadsf",
"description":"One of the best Mexican restaurants in San Francisco"
}
]
}
{
"data": [
{
"restaurant_id": "5",
"name":"El Farolito",
"phone":"415 580 1405",
"email":"el.farolito@gmail.com",
"floorplan":"fasdfasdfasdfasdfasdfasdfadsf",
"description":"One of the best Mexican restaurants in San Francisco"
},
{
"restaurant_id": "6",
"name":"Shanghai Dumpling King",
"phone":"415 570 1405",
"email":"dumplings@gmail.com",
"floorplan":"fasdfasdfasdfasdfasdfasdfadsf",
"description":"Chinese restaurant in SF"
},
{
"restaurant_id": "7",
"name":"Grinders Pizzeria",
"phone":"415 560 1405",
"email":"grinders@gmail.com",
"floorplan":"fasdfasdfasdfasdfasdfasdfadsf",
"description":"This is a wonderful pizzeria"
}
]
}
"The real-time web is fundamentally different from traditional web apps since there is no knowing when, or if, a response will be received."
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1833842/Notificaci_n-push.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1833845/b7702634f82d076d9bdc2fa5f6dfa94f-1.jpg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1833849/cakebet.jpg)
Push notifications
Chat
Gaming
Traditional Web Apps
- Stateless
- No persistent connections
- One-directional
- Ajax for asynchronous updates
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1828452/pasted-from-clipboard.png)
Difficult to build real time applications
Real Time Communication?
Long polling
- Javascript polls the server
- Inefficient
Plugins & extensions
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829288/Adobe_Flash_Player_v10_icon.png)
- Install required
- Inefficient
- Security concerns
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829289/java-1.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829295/Link_Artwork_2__The_Minish_Cap_.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829300/logo.png)
Websockets & WebRTC
Socket.IO
Let's talk about horrible browser support
Let's talk about some other downsides
Websockets
- Bi-directional socket connection
- No plugins, straight Javascript
- TCP Socket
- Supports HTTP/HTTPS
- Great Browser Support
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829472/pullout-browser-icons-0ddeb4fe78d0a3fe3fef4d89dd826315.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829425/WebSockets2.png)
Code Example
//create a websocket object
var exampleSocket = new WebSocket("ws://www.example.com/socketserver");
//sending a message
exampleSocket.send("Here's some text that the server is urgently awaiting!");
//receiving a message
exampleSocket.onmessage = function (event) {
console.log(event.data);
}
Libraries
- Create rooms
- Handle sessions
- broadcast messages
- Fallbacks for older browsers
- Streamlined API's
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829634/socketio2.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829660/autobahn_ws.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829662/996163.png)
Don't want to write a server?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829643/687474703a2f2f692e696d6775722e636f6d2f4b52544f7738642e706e67.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829644/pusher-logo.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829647/pn1.png)
WebRTC
- Web Real Time Communication
- Uses UDP
- Unreliable Stream
- Extremely fast, but potential data loss
- Peer to Peer
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829714/webrtc.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829723/jsep.png)
WebRTC Visualized
Use Cases
- Real Time Gaming
- VOIP Calls
- Video Conferencing
- Music Streaming
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1829727/election-commission1.jpg)
But...
- low level compared to websockets
- Still very early
- Experimental
- Only supported in Chrome and Firefox
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1833864/201404-WebRTC-browser-support.png)
Conclusion
Protocol | TCP (reliable) | UDP (unreliable) |
Connection Type | Peer To Peer | Client/Server |
Browser Support | All Major | Firefox/Chrome |
Speed | Slower | Very fast |
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1833875/xws_tornado.png.pagespeed.ic.VZ8my8NYAX.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/389352/images/1833876/webrtc.png)
QUESTIONS?
Websockets
By Jens Vanderhaeghe
Websockets
- 820