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
jmyz0455
V2EX  ›  Python

有谁搞过 Python 的 Websocket Client ?请教几个问题。

  •  
  •   jmyz0455 · 2019-02-18 17:09:01 +08:00 · 2303 次点击
    这是一个创建于 1887 天前的主题,其中的信息可能已经有所发展或是发生改变。

    网上的文档太少了,先问第一个问题,如何订阅指定频道?

    翻遍了谷歌也找不到,我看到不少文章都是写的:

    ws.send(json.dumps({"event":"subscribe","channel":"trades"})

    想不通,这个只是普通发消息的方法,哪门子是订阅啊?

    4 条回复    2019-02-21 10:51:26 +08:00
    winix
        1
    winix  
       2019-02-18 21:01:22 +08:00
    一般在 URL 中的 path 部分指定。这也要看 Server 端的实现,或者说是约定了。
    jmyz0455
        2
    jmyz0455  
    OP
       2019-02-19 09:58:38 +08:00
    @winix 订阅能在 path 里直接指定?就是类似 ws.subscribe(url) 的方法也不需要?
    jenlors
        3
    jenlors  
       2019-02-20 23:35:45 +08:00
    主要看服务端是怎么弄的,要么是 url 中指定,要么连接成功后发送一个消息过去。
    jmyz0455
        4
    jmyz0455  
    OP
       2019-02-21 10:51:26 +08:00
    @long2ice 已经找到实现方法了,跟服务的无关,是框架的机制。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2953 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 03:42 · PVG 11:42 · LAX 20:42 · JFK 23:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.