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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
Claude Code × Gemini × Ebitengine ゲーム制作素人WebエンジニアがGoでゲームを作った話
webzawa
0
150
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.6k
UIの境界線をデザインする | React Tokyo #15 メイントーク
sasagar
2
380
ついに来た!本格的なマルチクラウド時代の Google Cloud
maroon1st
0
220
[RubyKaigi 2026] Require Hooks
palkan
1
220
Angular Signal Forms
debug_mode
0
120
JOAI2026 1st solution - heron0519 -
heron0519
0
140
Offline should be the norm: building local-first apps with CRDTs & Kotlin Multiplatform
renaudmathieu
0
220
AIエージェントで業務改善してみた
taku271
0
540
Oxlintとeslint-plugin-react-hooks 明日から始められそう?
t6adev
0
280
Cache-moi si tu peux : patterns et pièges du cache en production - Devoxx France 2026 - Conférence
slecache
0
280
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
180
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
199
73k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.4k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Site-Speed That Sticks
csswizardry
13
1.2k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
180
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
150
The Invisible Side of Design
smashingmag
303
52k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
510
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
エンジニアに許された特別な時間の終わり
watany
106
240k
Designing for Performance
lara
611
70k
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!