Your SlideShare is downloading. ×
0
withServer-Sent Events                  @cppgohan
Flask?
Flask?MicroFramework again...
Flask?MicroFramework again...Written in Python
=
=
=WerkzeugWSGI utility library
=                       +WerkzeugWSGI utility library
=                       +WerkzeugWSGI utility library
=                       +Werkzeug                   Jinja2WSGI utility library       template engine
DemoHello.py
DemoHello.py
DemoHello.py
Demoindex.html
Demoindex.htmlresult???
Demoindex.htmlresult???  • terminal run: python hello.py  • open http://localhost:5000
Server-Sent Eventserver push的html5标准, 用法简易, 单次连接比polling高效些.相比websocket的双向二进制数据, Server-Sent Event只是单向, HTTP协议.(但浏览器调试工具往往...
Server-Sent Event
Server-Sent Event             支                 持                 率                   不              要  能 高, 暂            ...
Demoindex.html
Demohello.py
Demoredis:
Demoredis:   demo:FILE_TEXT -- 每次python读出来的文本   demo:FILE_TEXT_SEQ -- 为文本版本号, 每次文本更新, 版本号+1   /sever_push响应 -- 当FILE_TEXT_...
Demoresult???
Demoresult???  • terminal run: python hello.py
Demoresult???  • terminal run: python hello.py  • open http://localhost:5000
Demoresult???  • terminal run: python hello.py  • open http://localhost:5000  • block!!!
Demoresult???  • terminal run: python hello.py  • open http://localhost:5000  • block!!!solution???
Demoresult???  • terminal run: python hello.py  • open http://localhost:5000  • block!!!solution???  • async WSGI server! ...
Demoresult???  • terminal run: python hello.py  • open http://localhost:5000  • block!!!solution???  • async WSGI server! ...
Demoresult???  • terminal run: python hello.py  • open http://localhost:5000  • block!!!solution???  • async WSGI server! ...
Demoresult???  • terminal run: python hello.py  • open http://localhost:5000  • block!!!solution???  • async WSGI server! ...
More DemoServer下发代码示例
More DemoServer下发代码示例• start http://localhost:5000        web server• open push js script...  • server excute js script......
More Usage• 网站动态更新• 区分客户端推送• 微博墙实现• webgame服务器推送• 浏览器插件
Resources• http://www.python.org/dev/peps/pep-0333/• http://werkzeug.pocoo.org/• http://jinja.pocoo.org/• http://flask.poc...
END; 2013, 分享不止!
Upcoming SlideShare
Loading in...5
×

Flask With Server-Sent Event

2,267

Published on

Flask With Server-Sent Event by cppgohan
sztechparty 20130317

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,267
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
33
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Flask With Server-Sent Event"

  1. 1. withServer-Sent Events @cppgohan
  2. 2. Flask?
  3. 3. Flask?MicroFramework again...
  4. 4. Flask?MicroFramework again...Written in Python
  5. 5. =
  6. 6. =
  7. 7. =WerkzeugWSGI utility library
  8. 8. = +WerkzeugWSGI utility library
  9. 9. = +WerkzeugWSGI utility library
  10. 10. = +Werkzeug Jinja2WSGI utility library template engine
  11. 11. DemoHello.py
  12. 12. DemoHello.py
  13. 13. DemoHello.py
  14. 14. Demoindex.html
  15. 15. Demoindex.htmlresult???
  16. 16. Demoindex.htmlresult??? • terminal run: python hello.py • open http://localhost:5000
  17. 17. Server-Sent Eventserver push的html5标准, 用法简易, 单次连接比polling高效些.相比websocket的双向二进制数据, Server-Sent Event只是单向, HTTP协议.(但浏览器调试工具往往没法看到服务器发来的数据, X_X) Server对Client的请求, 做stream方式的响应.
  18. 18. Server-Sent Event
  19. 19. Server-Sent Event 支 持 率 不 要 能 高, 暂 兼 ”玩” 时 容 只 处 理
  20. 20. Demoindex.html
  21. 21. Demohello.py
  22. 22. Demoredis:
  23. 23. Demoredis: demo:FILE_TEXT -- 每次python读出来的文本 demo:FILE_TEXT_SEQ -- 为文本版本号, 每次文本更新, 版本号+1 /sever_push响应 -- 当FILE_TEXT_SEQ增加时, 将最新的文本返回给浏览器
  24. 24. Demoresult???
  25. 25. Demoresult??? • terminal run: python hello.py
  26. 26. Demoresult??? • terminal run: python hello.py • open http://localhost:5000
  27. 27. Demoresult??? • terminal run: python hello.py • open http://localhost:5000 • block!!!
  28. 28. Demoresult??? • terminal run: python hello.py • open http://localhost:5000 • block!!!solution???
  29. 29. Demoresult??? • terminal run: python hello.py • open http://localhost:5000 • block!!!solution??? • async WSGI server! (eg. gunicorn + gevent, gevent)
  30. 30. Demoresult??? • terminal run: python hello.py • open http://localhost:5000 • block!!!solution??? • async WSGI server! (eg.-kgunicorn-bgevent, gevent)hello:app + • terminal run: gunicorn gevent 0.0.0.0:5000
  31. 31. Demoresult??? • terminal run: python hello.py • open http://localhost:5000 • block!!!solution??? • async WSGI server! (eg.-kgunicorn-bgevent, gevent)hello:app + • terminal run: gunicorn gevent 0.0.0.0:5000 • open http://localhost:5000
  32. 32. Demoresult??? • terminal run: python hello.py • open http://localhost:5000 • block!!!solution??? • async WSGI server! (eg.-kgunicorn-bgevent, gevent)hello:app + • terminal run: gunicorn gevent 0.0.0.0:5000 • open http://localhost:5000 again! • open http://localhost:5000
  33. 33. More DemoServer下发代码示例
  34. 34. More DemoServer下发代码示例• start http://localhost:5000 web server• open push js script... • server excute js script... • browser • ...
  35. 35. More Usage• 网站动态更新• 区分客户端推送• 微博墙实现• webgame服务器推送• 浏览器插件
  36. 36. 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
  37. 37. END; 2013, 分享不止!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×