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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
74
Other Decks in Programming
See All in Programming
Domain-Driven Transformation
hschwentner
2
2.3k
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
0
110
Performance Optimization With LLMs
xleitix
0
160
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
160
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.2k
Agents on Rails - Rails at Scale 2026
irinanazarova
0
570
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
2
930
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
330
Next.js: The final boss of Web Performance
guaca
0
290
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
4k
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
Featured
See All Featured
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
850
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Rails Girls Zürich Keynote
gr2m
96
14k
Paper Plane
katiecoart
PRO
5
54k
Building Adaptive Systems
keathley
44
3.3k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
How GitHub (no longer) Works
holman
316
150k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.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!