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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
77
Introduction to Bittorrent sync
gohan
0
100
Twitter bootstrap 小试
gohan
0
110
Introduction To Hubot
gohan
1
230
Other Decks in Technology
See All in Technology
20年前の「OSS革命」に学ぶ AI時代の生存戦略
samakada
0
380
AWS Agent Registry の基礎・概要を理解する/aws-agent-registry-intro
ren8k
3
360
Standards et agents IA : un tour d’horizon de MCP, A2A, ADK et plus encore
glaforge
0
140
JEDAI in Osaka 2026イントロ
taka_aki
0
320
2026年、知っておくべき最新 サーバレスTips10選/serverless-10-tips
slsops
13
5.1k
明日からドヤれる!超マニアックなAWSセキュリティTips10連発 / 10 Ultra-Niche AWS Security Tips
yuj1osm
0
560
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
6
74k
職能の壁を取り払った先で見えた壁 -AI時代のクロスファンクショナル組織-
shimotaroo
1
120
Practical TypeProf: Lessons from Analyzing Optcarrot
mame
0
130
Digitization部 紹介資料
sansan33
PRO
1
7.3k
MLOps導入のための組織作りの第一歩
akasan
0
320
サイボウズ 開発本部採用ピッチ / Cybozu Engineer Recruit
cybozuinsideout
PRO
10
78k
Featured
See All Featured
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
500
Between Models and Reality
mayunak
3
260
Into the Great Unknown - MozCon
thekraken
40
2.4k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
30 Presentation Tips
portentint
PRO
1
270
A better future with KSS
kneath
240
18k
WCS-LA-2024
lcolladotor
0
540
Building Flexible Design Systems
yeseniaperezcruz
330
40k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
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, 分享不止!