V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
shenlei
V2EX  ›  Python

websocket 怎么实时发送数据到网页?

  •  
  •   shenlei · 2016-07-25 11:15:55 +08:00 · 4926 次点击
    这是一个创建于 2830 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我后台用的是 python 库中的一个 websocket 模块 simplewebsocketserver https://github.com/dpallot/simple-websocket-server ,在收到前台命令之后,会一次发送几十条数据:主要就是在 handleMessage 函数中循环调用 sendlemessage 函数,但是我发现在调用之后数据包并没有立即发送给 web 页面啊。这些数据实际上也的确是分开发送的,所以我怀疑是不是在退出 handlemessage 函数退出之后才开始发送数据?我想实现的就是立即发送给页面,不用等待。谢谢大家了。

    3 条回复    2016-07-25 13:34:40 +08:00
    septem123
        1
    septem123  
       2016-07-25 11:58:33 +08:00
    这个时候你需要的是 socket.io
    我自己用的是 node 版的
    python 版的 https://github.com/miguelgrinberg/python-socketio
    Kilerd
        2
    Kilerd  
       2016-07-25 13:33:04 +08:00 via Android
    gevent websocket 也可以用一下
    Kilerd
        3
    Kilerd  
       2016-07-25 13:34:40 +08:00 via Android
    如果是 flask 可以用 flask socket s
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5256 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 01:16 · PVG 09:16 · LAX 18:16 · JFK 21:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.