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
flask with server-sent events
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
cppgohan
January 13, 2013
Technology
1.9k
4
Share
flask with server-sent events
sztechparty
cppgohan
January 13, 2013
More Decks by cppgohan
See All by cppgohan
ReactNative for Android first look
gohan
0
80
Introduction to Bittorrent sync
gohan
0
120
Twitter bootstrap 小试
gohan
0
110
Introduction To Hubot
gohan
1
230
Other Decks in Technology
See All in Technology
テストコードのないプロジェクトにテストを根付かせる
tttol
0
230
関西に縁あるMicrosoft MVPsが語るCopilotの未来
kasada
0
540
海外カンファレンス「JavaOne」参加レポート ユーザー系IT企業における目的・成果/JavaOne Report Purpose and Results in the User IT Company
muit
0
120
AIが変えた"品質の守り方"
kkakizaki
13
5.4k
Javaコミュニティをもっと楽しむための9箇条
takasyou
0
720
Claude Codeを組織で使いこなす— サーバサイドAIエージェント運用の実践知
techtekt
PRO
0
130
long-running-tasks
cipepser
2
450
速さだけじゃない! VoidZero ツールが移行先に選ばれる理由
mizdra
PRO
6
700
コードレビューを制するチームがソフトウェアデリバリーのフローを制す / Beyond Code Review: Distributing Its Responsibilities Across the SDLC
mtx2s
3
480
Databricks 月刊サービスアップデート 2026年05月号
tyosi1212
0
120
NFLコンペ2026 解法
lycorptech_jp
PRO
0
130
CloudFront VPCオリジンとVPC Latticeサービスの内部ALBをマルチアカウントで一元利用しよう
duelist2020jp
5
260
Featured
See All Featured
Mind Mapping
helmedeiros
PRO
1
220
YesSQL, Process and Tooling at Scale
rocio
174
15k
Marketing to machines
jonoalderson
1
5.3k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
230
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
580
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Building Flexible Design Systems
yeseniaperezcruz
330
40k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1.1k
Technical Leadership for Architectural Decision Making
baasie
3
380
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
Transcript
@cppgohan with Server-Sent Events
Flask?
Flask? MicroFramework again...
Flask? MicroFramework again... Written in Python
=
=
Werkzeug WSGI utility library =
+ Werkzeug WSGI utility library =
+ Werkzeug WSGI utility library =
+ Werkzeug WSGI utility library Jinja2 template engine =
Hello.py Demo
Hello.py Demo
Hello.py Demo
index.html Demo
index.html Demo result???
index.html Demo result??? • terminal run: python hello.py • open
http://localhost:5000
Server-Sent Event server push的html5标准, 用法简易, 单次连接比polling高效些. 相比websocket的双向二进制数据, Server-Sent Event只是单向, HTTP协议.
(但浏览器调试工具往往没法看到服务器发来的数据, X_X) Server对Client的请求, 做stream方式的响应.
Server-Sent Event
Server-Sent Event 支 持 率 不 高 , 暂 时
只 能 ”玩 ” 要 兼 容 处 理
Demo index.html
Demo hello.py
Demo redis:
Demo redis: demo:FILE_TEXT -- 每次python读出来的文本 demo:FILE_TEXT_SEQ -- 为文本版本号, 每次文本更新, 版本号+1
/sever_push响应 -- 当FILE_TEXT_SEQ增加时, 将最新的文本返回给浏览器
Demo result???
Demo result??? • terminal run: python hello.py
Demo result??? • terminal run: python hello.py • open http://localhost:5000
Demo result??? • terminal run: python hello.py • open http://localhost:5000
• block!!!
Demo result??? • terminal run: python hello.py • open http://localhost:5000
• block!!! solution???
Demo result??? • terminal run: python hello.py • open http://localhost:5000
• block!!! • async WSGI server! (eg. gunicorn + gevent, gevent) solution???
Demo result??? • terminal run: python hello.py • open http://localhost:5000
• block!!! • async WSGI server! (eg. gunicorn + gevent, gevent) • terminal run: gunicorn -k gevent -b '0.0.0.0:5000' hello:app solution???
Demo result??? • terminal run: python hello.py • open http://localhost:5000
• block!!! • async WSGI server! (eg. gunicorn + gevent, gevent) • terminal run: gunicorn -k gevent -b '0.0.0.0:5000' hello:app • open http://localhost:5000 solution???
Demo result??? • terminal run: python hello.py • open http://localhost:5000
• block!!! • async WSGI server! (eg. gunicorn + gevent, gevent) • terminal run: gunicorn -k gevent -b '0.0.0.0:5000' hello:app • open http://localhost:5000 • open http://localhost:5000 again! solution???
More Demo Server下发代码示例
More Demo • start web server • open http://localhost:5000 •
server push js script... • browser excute js script... • ... Server下发代码示例
More Usage •网站动态更新 •区分客户端推送 •微博墙实现 •webgame服务器推送 •浏览器插件
Resources • http://www.python.org/dev/peps/pep-0333/ • http://werkzeug.pocoo.org/ • http://jinja.pocoo.org/ • http://flask.pocoo.org/ •
http://www.gevent.org/ • http://gunicorn.org/ • http://dev.w3.org/html5/eventsource/ • http://www.html5rocks.com/en/tutorials/eventsource/basics/ • http://www.w3schools.com/html/html5_serversentevents.asp
END; 2013, 分享不止!