Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
NodeJS + SocketIO
Search
Federico Ravasio
October 15, 2012
Programming
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
NodeJS + SocketIO
Lightning talk @ Codelovers.
Federico Ravasio
October 15, 2012
More Decks by Federico Ravasio
See All by Federico Ravasio
The art of Mocking
razielgn
1
200
Concurrency vs. Parallelism 2.0 - RubyDay 2013
razielgn
3
200
Concurrency vs. Parallelism - Codelovers 2013
razielgn
3
210
Guida intergalattica per contributori Open Source
razielgn
0
75
Other Decks in Programming
See All in Programming
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
320
Inertia Rails: The One-Person Framework with React & Friends
skryukov
0
380
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
180
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
1
290
Railsバージョンを4倍にした話
optim
0
920
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
3
1.7k
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
170
AI Augmentation Techniques with Liberty
ivargrimstad
1
360
Distance field of Julia set
kinakomoti321
0
150
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
410
Snowflake Openflow Connector利用の勘所 / 20261024developersio2026tokyo-snowflake-openflow
kasacchiful
PRO
0
290
Seven New Principles of Software Engineering
yegor256
0
440
Featured
See All Featured
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
520
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
800
Into the Great Unknown - MozCon
thekraken
41
2.8k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.9k
The Curious Case for Waylosing
cassininazir
1
610
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
Building AI with AI
inesmontani
PRO
1
1.4k
Transcript
+
Orientato agli eventi I/O asincrono Reactor pattern Google V8 Singolo
thread
Websocket con fallback Semplice messaggistica
None
“In attesa di uno straniero...” “Stai parlando con uno straniero,
salutalo!” Straniero: asl? Tu: 98 m antarctica Straniero: o_o” [Qualcuno lascia la chat]
Server
var waiting = []; // Lista client in attesa var
couples = {}; // { // clientID: stranger, // strangerID: client // ... // }
var io = SocketIO.listen(server); // server è un server HTTP
già inizializzato io.sockets.on('connection', function(client) { // ... });
io.sockets.on('connection', function(client) { if (waiting.length == 0) { waiting.push(client); client.emit('waiting');
} else { var stranger = waiting.pop(); couples[client.id] = stranger; couples[stranger.id] = client; client.emit('partner'); stranger.emit('partner'); } // ... });
io.sockets.on('connection', function(client) { // ... client.on('message', function(message) { couples[client.id].emit('message', message);
}); // ... });
io.sockets.on('connection', function(client) { // ... client.on('disconnect', function() { if (stranger
= couples[client.id]) { stranger.emit('left'); delete couples[stranger.id]; delete couples[client.id]; } }); });
Client
var socket = io.connect(); socket.on('waiting', function() { logMessage('Waiting for a
stranger...'); }); socket.on('partner', function() { logMessage('You are now chatting with...'); }); socket.on('message', function(message) { logMessage(message); }); socket.on('left', function() { this.logMessage('Stranger has left...'); socket.disconnect(); });
var leaveConversation = function() { logMessage('You have left...'); socket.disconnect(); };
var sendMessage = function(message) { socket.emit('message', message); logMessage(message); };
Demo!