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
cppgohan
January 13, 2013
Technology
4
1.8k
flask with server-sent events
sztechparty
cppgohan
January 13, 2013
Tweet
Share
More Decks by cppgohan
See All by cppgohan
ReactNative for Android first look
gohan
0
57
Introduction to Bittorrent sync
gohan
0
92
Twitter bootstrap 小试
gohan
0
94
Introduction To Hubot
gohan
1
220
Other Decks in Technology
See All in Technology
依存関係があるコンポーネントは Barrel ファイルでまとめよう
azukiazusa1
3
530
現場の種を事業の芽にする - エンジニア主導のイノベーションを事業戦略に装着する方法 -
kzkmaeda
2
1.5k
モノレポ開発のエラー、誰が見る?Datadog で実現する適切なトリアージとエスカレーション
biwashi
6
770
High Performance PHP
cmuench
0
140
AWSでRAGを実現する上で感じた3つの大事なこと
ymae
3
1k
Datadog APM におけるトレース収集の流れ及び Retention Filters のはなし / datadog-apm-trace-retention-filters
k6s4i53rx
0
320
プロセス改善による品質向上事例
tomasagi
1
1.6k
AndroidデバイスにFTPサーバを建立する
e10dokup
0
240
第13回 Data-Centric AI勉強会, 画像認識におけるData-centric AI
ksaito_osx
0
360
PL900試験から学ぶ Power Platform 基礎知識講座
kumikeyy
0
110
SCSAから学ぶセキュリティ管理
masakamayama
0
140
マルチモーダル理解と生成の統合 DeepSeek Janus, etc... / Multimodal Understanding and Generation Integration
hiroga
0
360
Featured
See All Featured
Done Done
chrislema
182
16k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
A better future with KSS
kneath
238
17k
Speed Design
sergeychernyshev
25
780
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Music & Morning Musume
bryan
46
6.3k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
630
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.8k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
27
1.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
51k
How to Think Like a Performance Engineer
csswizardry
22
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, 分享不止!