Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
NodeJS + SocketIO
Search
Federico Ravasio
October 15, 2012
Programming
0
150
NodeJS + SocketIO
Lightning talk @ Codelovers.
Federico Ravasio
October 15, 2012
Tweet
Share
More Decks by Federico Ravasio
See All by Federico Ravasio
The art of Mocking
razielgn
1
180
Concurrency vs. Parallelism 2.0 - RubyDay 2013
razielgn
3
170
Concurrency vs. Parallelism - Codelovers 2013
razielgn
3
180
Guida intergalattica per contributori Open Source
razielgn
0
52
Other Decks in Programming
See All in Programming
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
230
認証・認可の基本を学ぼう後編
kouyuume
0
250
Cell-Based Architecture
larchanjo
0
140
実は歴史的なアップデートだと思う AWS Interconnect - multicloud
maroon1st
0
250
ゆくKotlin くるRust
exoego
1
150
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
410
堅牢なフロントエンドテスト基盤を構築するために行った取り組み
shogo4131
8
2.5k
tparseでgo testの出力を見やすくする
utgwkk
2
270
AtCoder Conference 2025「LLM時代のAHC」
imjk
2
570
Combinatorial Interview Problems with Backtracking Solutions - From Imperative Procedural Programming to Declarative Functional Programming - Part 2
philipschwarz
PRO
0
110
Developing static sites with Ruby
okuramasafumi
0
320
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
350
Featured
See All Featured
The Spectacular Lies of Maps
axbom
PRO
1
400
Color Theory Basics | Prateek | Gurzu
gurzu
0
150
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.7k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
115
91k
Mind Mapping
helmedeiros
PRO
0
38
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
0
250
[RailsConf 2023] Rails as a piece of cake
palkan
58
6.2k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
130
SEO for Brand Visibility & Recognition
aleyda
0
4.1k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
16
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
80
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!