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
120
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.4k
Kosko - 改用 JavaScript 來管理 Kubernetes YAML (COSCUP 2021)
tommy351
0
120
Kubernetes 101
tommy351
2
320
Fast Web Development with Express
tommy351
0
140
An Introduction to Node.js
tommy351
1
360
Other Decks in Programming
See All in Programming
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
7.6k
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
1
350
スマート反転とウェブアクセシビリティ
camiha
0
210
SONY CISC-NEWS NWS-1750 + NWB-225 フレームバッファの NetBSD/news68k ドライバ実装 / OSC2026Hiroshima
tsutsui
0
120
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
2.2k
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.1k
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
540
新卒PdEのリアル
ryu1013
1
510
The Rails Doctrine Decade
koic
2
170
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
250
wkhtmltopdfの次どうするか問題2026
willnet
2
1.5k
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
450
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
135
10k
GitHub's CSS Performance
jonrohan
1033
470k
Product Roadmaps are Hard
iamctodd
55
13k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
700
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Done Done
chrislema
186
16k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
550
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