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
180
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
69
Other Decks in Programming
See All in Programming
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
2.9k
광주소프트웨어마이스터고등학교 DevFest 특강 - 바이브 코딩 시대에서 주니어 개발자로 살아남는 방법
utilforever
1
150
どこまでゆるくて許されるのか
tk3fftk
0
520
5分で問診!Composer セキュリティ健康診断
codmoninc
0
560
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
150
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
690
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
180
Foundation Models frameworkで画像分析
ryodeveloper
1
130
フィードバックで育てるAI開発
kotaminato
1
120
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
280
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
130
yield再入門 #phpcon
o0h
PRO
0
710
Featured
See All Featured
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
500
Product Roadmaps are Hard
iamctodd
55
12k
Odyssey Design
rkendrick25
PRO
2
730
Google's AI Overviews - The New Search
badams
0
1.1k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
280
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
470
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
220
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
880
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
200
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
410
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!