web in real time - technical project - socket.io

Post on 15-Aug-2015

216 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Socket.ioWeb in Real-time

/ Thomas Ferney Clément De Figueiredo

http://realtimeweb.antiseptikk.fr

Summary

Concept introduction

Real-time communication methods

Node.js

Socket.io

Applications

Conclusion

Web in Real-timeCollaborative + Multi-screen + New contexts

Real-time communicationmethods

Pooling made every secondsOvercharged risk in case of overcrowding

Ajax Long PoolingPooling variation

Connection open waiting for dataConnection closed by a response or a timeout

Many connections open at once

Ajax Multipart StreamingMethod based on Gecko(Netscape Navigator, Firefox...)

Adding the parameter multipart = true to the XMLHttpRequest objectUse of multipart/x-mixed-replace content that will stream data

Forever iframeHidding an iframe with the mentions :

Transfer-encoding : chunkedConnection : keep-alive

Infinite loading bar on some browser

WebSocketsBi-directionnal communication over a TCP socket

Standards methods on every browser

Runtime environment for JavaScript programs developed in C++Code interpretation with the V8 engine of Google

Library of modules managed with NPM

Server creationvar http = require('http'), fs = require('fs');

http.createServer(function(req, res)

res.writeHead(200, 'Content­Type': 'text/html', 'Access­Control­Allow­Origin': '*' );

var readStream = fs.createReadStream(__dirname + '/index.html');

readStream.pipe(res);

).listen(3000);

console.log('http://localhost:3000');

Framework JavaScript using WebSocketsEnhanced support for browsers

Available from NPM

Exemple of server implementationvar app = require('http').createServer(handler);var io = require('socket.io')(app);var fs = require('fs');

app.listen(80);

function handler (req, res) fs.readFile(__dirname + '/index.html', function (err, data) res.writeHead(200); res.end(data); );

io.on('connection', function(socket) socket.emit('news', hello: 'world' ););

Exemple of client implementation<script src="/socket.io/socket.io.js"></script><script>

</script>

var socket = io('http://localhost');

socket.on('news', function (data) console.log(data); );

Monitoring appDaemon in C

MySQL databaseDashboard in HTML / JavaScript on a Node.js server

2:19

Collaboratives shopping lists appMongoDB database

AngularJS web app on a Node.js server

1:36

Conclusion

Node.jsEasy to usePowerful

Socket.ioAbstractionAPI well-stocked

Real-time in few lines

4:48

Thanks a lot !Contact : / @MrAntiseptikk @CaptainKali

top related