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
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
カツオ、ご期待ください
suneo3476
0
170
R8 の設定見直しでアプリサイズ削減
andpad
0
210
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
200
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
160
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
0
1.2k
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2.3k
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1k
パーソナライズPodcastを作った話
repunit11
0
140
Kubernetes祭り #2 OP/ED
bells17
0
110
JRuby: Past, Present, and Future
headius
0
230
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
140
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
450
From π to Pie charts
rasagy
1
400
The untapped power of vector embeddings
frankvandijk
2
1.9k
The Limits of Empathy - UXLibs8
cassininazir
2
720
Six Lessons from altMBA
skipperchong
29
4.5k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Deep Space Network (abreviated)
tonyrice
0
370
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
280
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!