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
Federico Ravasio
October 15, 2012
Programming
160
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
60
Other Decks in Programming
See All in Programming
Spec Driven Development | AI Summit Vilnius
danielsogl
PRO
1
110
AI時代のPhpStorm最新事情 #phpcon_odawara
yusuke
0
190
SkillがSkillを生む:QA観点出しを自動化した
sontixyou
6
3.5k
ソフトウェア設計の結合バランス #phperkaigi
kajitack
0
140
ハーネスエンジニアリングにどう向き合うか 〜ルールファイルを超えて開発プロセスを設計する〜 / How to approach harness engineering
rkaga
24
14k
ふりがな Deep Dive try! Swift Tokyo 2026
watura
0
230
Cache-moi si tu peux : patterns et pièges du cache en production - Devoxx France 2026 - Conférence
slecache
0
280
実践CRDT
tamadeveloper
0
590
t *testing.T は どこからやってくるの?
otakakot
1
710
AIを導入する前にやるべきこと
negima
2
150
Agentic Elixir
whatyouhide
0
390
Road to RubyKaigi: Play Hard(ware)
makicamel
1
410
Featured
See All Featured
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
720
What's in a price? How to price your products and services
michaelherold
247
13k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
140
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Designing Experiences People Love
moore
143
24k
Making Projects Easy
brettharned
120
6.6k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
The World Runs on Bad Software
bkeepers
PRO
72
12k
How GitHub (no longer) Works
holman
316
150k
Become a Pro
speakerdeck
PRO
31
5.9k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.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!