Upgrade to Pro — share decks privately, control downloads, hide ads and more …

flask with server-sent events

cppgohan
January 13, 2013

flask with server-sent events

sztechparty

cppgohan

January 13, 2013
Tweet

More Decks by cppgohan

Other Decks in Technology

Transcript

  1. =

  2. =

  3. Server-Sent Event server push的html5标准, 用法简易, 单次连接比polling高效些. 相比websocket的双向二进制数据, Server-Sent Event只是单向, HTTP协议.

    (但浏览器调试工具往往没法看到服务器发来的数据, X_X) Server对Client的请求, 做stream方式的响应.
  4. Server-Sent Event 支 持 率 不 高 , 暂 时

    只 能 ”玩 ” 要 兼 容 处 理
  5. Demo result??? • terminal run: python hello.py • open http://localhost:5000

    • block!!! • async WSGI server! (eg. gunicorn + gevent, gevent) solution???
  6. 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???
  7. 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???
  8. 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???
  9. More Demo • start web server • open http://localhost:5000 •

    server push js script... • browser excute js script... • ... Server下发代码示例
  10. 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