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
54
Introduction to Bittorrent sync
gohan
0
91
Twitter bootstrap 小试
gohan
0
93
Introduction To Hubot
gohan
1
220
Other Decks in Technology
See All in Technology
Taming you application's environments
salaboy
0
200
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
210
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
600
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
CDCL による厳密解法を採用した MILP ソルバー
imai448
3
180
Lexical Analysis
shigashiyama
1
150
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
1
120
OS 標準のデザインシステムを超えて - より柔軟な Flutter テーマ管理 | FlutterKaigi 2024
ronnnnn
1
300
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
110
FlutterアプリにおけるSLI/SLOを用いたユーザー体験の可視化と計測基盤構築
ostk0069
0
110
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
Featured
See All Featured
A designer walks into a library…
pauljervisheath
204
24k
Writing Fast Ruby
sferik
627
61k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
How to train your dragon (web standard)
notwaldorf
88
5.7k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
What's new in Ruby 2.0
geeforr
343
31k
Optimizing for Happiness
mojombo
376
70k
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, 分享不止!