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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
190
Concurrency vs. Parallelism - Codelovers 2013
razielgn
3
200
Guida intergalattica per contributori Open Source
razielgn
0
72
Other Decks in Programming
See All in Programming
Google Apps Script で Ruby を動かす
kawahara
0
220
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
710
Flow は今どうなっているか
mizdra
PRO
0
510
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
18k
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
270
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
240
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
1.7k
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
490
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
380
楽しそうなつよつよエンジニアと目が死んでる僕/A brilliant engineer having a blast, and dead-eyed me.
3l4l5
2
180
Built Our Own Background Agent at LayerX
layerx
PRO
10
5.4k
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
210
Featured
See All Featured
Speed Design
sergeychernyshev
33
2k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
410
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Embracing the Ebb and Flow
colly
88
5.1k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
460
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
430
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
340
Optimizing for Happiness
mojombo
378
71k
Google's AI Overviews - The New Search
badams
0
1.1k
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!