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
Socket.io 即時通訊實作
Search
Tommy Chen
December 04, 2014
Programming
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Socket.io 即時通訊實作
Tommy Chen
December 04, 2014
More Decks by Tommy Chen
See All by Tommy Chen
Kosko - 改用 JavaScript 來管理 Kubernetes YAML (Kubernetes Summit 2021)
tommy351
1
1.5k
Kosko - 改用 JavaScript 來管理 Kubernetes YAML (COSCUP 2021)
tommy351
0
150
Kubernetes 101
tommy351
2
350
Fast Web Development with Express
tommy351
0
160
An Introduction to Node.js
tommy351
1
380
Other Decks in Programming
See All in Programming
AI Augmentation Techniques with Liberty
ivargrimstad
1
420
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
300
GraphQL の onError と Nullability のこれから
quramy
0
210
AI-Powered Domain-Driven Design
ziobrando
0
420
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
420
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
290
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
240
Getting Started with Vibe Coding
miccheng
0
190
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
350
まずはコードより業務と向き合う:テーブル解体のためにPdMを呼んだ話
sakawe_ee
0
190
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
240
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
210
Featured
See All Featured
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
It's Worth the Effort
3n
188
29k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.9k
Rails Girls Zürich Keynote
gr2m
96
14k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Unsuck your backbone
ammeep
672
58k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
970
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.5k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
840
30 Presentation Tips
portentint
PRO
1
460
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
Transcript
⽰儘鸒鎝㻜⡲ ꤫㎗鰜!UPNNZ
䖎⛉䖎⛉⟃˘˘ ˖ 鰶鑉1PMMJOH ˖ 嫦ꥬ♧媯儘ぢ⠿剪㐼锞宠剓倞须俲 ˖ Ꟁ鰶鑉-POH1PMMJOH ˖ ⠿剪㐼莅㹐䨩畮⥃䭰鸮箁瘞䖊须俲刿倞 2
8FC4PDLFU ˖ 鸠䏞䘰 ˖ ⢪欽矦㋲ ˖ ⠿剪㐼莅㹐䨩畮〳ꦑ儘꧱ぢ彘鸒 ˖ *&♶佅䴂 3
None
8IZ4PDLFUJP ˖ ⢪欽矦㋲ ˖ 懳錒㐼♶佅䴂8FC4PDLFU儘荈⹛GBMMCBDL 5
㸞酤 npm install socket.io --save 6
&YQSFTT var express = require('express'); var app = express(); var
server = require('http').Server(app); var io = require('socket.io')(server); app.set('views', __dirname + '/views'); app.set('view engine', 'html'); app.engine('html', require('ejs').renderFile); app.get('/', function(req, res, next){ res.render('index'); }); server.listen(4000, function(){ console.log('Server started'); }); 7 䞕䲿銴 IUUQTTQFBLFSEFDLDPNUPNNZGBTUXFCEFWFMPQNFOUXJUIFYQSFTT
7JFX <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Chat room</title> </head>
<body> <script src="/socket.io/socket.io.js"></script> </body> </html> 8 鯺Ⰵ4PDLFUJPⴅ䒭䏨
姹鵔鎝䜂 9 畮 var socket = io.connect('http://localhost:4000'); socket.on('message', function(data){ alert(data.content);
}); 䖕畮 io.on('connection', function(socket){ socket.emit('message', {content: 'Hi there!'}); }); ⢪欽罏鸮箁ⵌ⠿剪㐼 ⠿剪㐼䱺佐ⵌ⢪欽罏涸鸮箁 ぢ⢪欽罏⫄鷑姹鵔鎝䜂 ⢪欽罏䱺佐ⵌ姹鵔鎝䜂
崩玑 10 使⽤用者 伺服器 ⢪欽罏鸮箁ⵌ⠿剪㐼 ぢ⢪欽罏⫄鷑姹鵔鎝䜂
1VC4VC垸䒭 ˖ 1VCMJTI4VCTDSJCF垸䒭 ˖ 㖈/PEFKT⚥⟃&WFOU&NJUUFS㻜⡲ 11 Subscriber Publisher 4VCTDSJCF PO
FWFOU 1VCMJTI FNJU FWFOU
䑞久 䑞久窍䨾剤⢪欽罏ꤑ✫荈䊹 socket.broadcast.emit('message', { content: 'Hi everyone!' }); 䑞久窍䨾剤⢪欽罏⺫䭍荈䊹 io.emit('message',
{ content: 'Hi everyone!' }); 12
翝㣔㹔 畮 var socket = io.connect('http://localhost:4000/room'); 䖕畮 io.of('/room').on('connection', function(socket){ console.log('User
connected to the room!'); }); 13
5IBOLT 14