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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
LLMは4年分のCompose移行を再現できるのか?実プロダクト279件のXMLで探る自動化の境界線
makun
0
260
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
380
Claude Codeを組織的に動かして月400PRを実現した話
happy_ryo
0
240
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.5k
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
270
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
570
Flow は今どうなっているか
mizdra
PRO
0
840
Swift愛好会と私(ウホーイ) / Swift Fan Club and Uhooi
uhooi
0
120
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.9k
AI時代に学ぶ 好きなルール 嫌いなルール Linter編
shorty5121
0
760
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
120
Go 1.27 における memory allocation の高速化
andpad
0
370
Featured
See All Featured
A designer walks into a library…
pauljervisheath
211
24k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
430
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
400
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
The Spectacular Lies of Maps
axbom
PRO
1
960
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Speed Design
sergeychernyshev
33
2.1k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
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!