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
190
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
73
Other Decks in Programming
See All in Programming
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
信頼性の目標を誰も求めてない
shubox
0
490
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
280
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
0
370
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
180
私のClaude Code活用法 (個人開発編) - PHPerKaigi mini #4(2026/08/24)
panda_program
1
210
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
0
230
新卒PdEのリアル
ryu1013
1
410
XHTMLが残したもの
yosuke_furukawa
PRO
1
410
型解析で実現する Go の言語内 DSL / Conference に Go! タイムテーブルの歩き方 for Gophers
mazrean
0
130
Laravelのアプリケーションをどこにデプロイするか #ツナギメオフライン.9
akase244
0
120
이 함수, 실패하면 어떻게 되나요? null부터 Rich Errors까지, Kotlin 에러 처리 15년
haeti2
0
130
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Google's AI Overviews - The New Search
badams
0
1.6k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
67
58k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
230
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.5k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Embracing the Ebb and Flow
colly
88
5.2k
The Cost Of JavaScript in 2023
addyosmani
55
10k
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!