Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
NodeJS + SocketIO
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Federico Ravasio
October 15, 2012
Programming
170
0
Share
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
190
Concurrency vs. Parallelism 2.0 - RubyDay 2013
razielgn
3
180
Concurrency vs. Parallelism - Codelovers 2013
razielgn
3
190
Guida intergalattica per contributori Open Source
razielgn
0
62
Other Decks in Programming
See All in Programming
サプライチェーン攻撃対策「層を重ねて落ちない壁」を10日間で組み上げた話 #TechLeadConf2026
kashewnuts
1
290
Structured Concurrency, Scoped Values and Joiners in the JDK 25 26 27
josepaumard
1
150
過去のレビュー知見をSkillsで資産化した話
pkshadeck
PRO
1
2k
20260514_its_the_context_window_stupid.pdf
heita
0
1k
PHPでバイナリをパースして理解するASN.1
muno92
PRO
0
460
PHPでローカル環境用のSSL/TLS証明書を発行することはできるのか? #phpconkagawa
akase244
0
370
Agentic Elixir
whatyouhide
0
450
ハーネスエンジニアリングとは?
kinopeee
13
7.1k
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
3.2k
Spec-Driven Development with AI Agents (Workshop, May 2026)
antonarhipov
3
380
Agent Skills を社内で育てる仕組み作り
jackchuka
1
2.1k
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
1
180
Featured
See All Featured
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
200
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.8k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.5k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.1k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
170
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
290
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3k
Code Review Best Practice
trishagee
74
20k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.3k
Side Projects
sachag
455
43k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
190
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!