推荐学习书目
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 · Feb 18, 2019 · 3028 views
    This topic created in 2665 days ago, the information mentioned may be changed or developed.

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

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

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

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

    4 replies    2019-02-21 10:51:26 +08:00
    winix
        1
    winix  
       Feb 18, 2019
    一般在 URL 中的 path 部分指定。这也要看 Server 端的实现,或者说是约定了。
    jmyz0455
        2
    jmyz0455  
    OP
       Feb 19, 2019
    @winix 订阅能在 path 里直接指定?就是类似 ws.subscribe(url) 的方法也不需要?
    jenlors
        3
    jenlors  
       Feb 20, 2019
    主要看服务端是怎么弄的,要么是 url 中指定,要么连接成功后发送一个消息过去。
    jmyz0455
        4
    jmyz0455  
    OP
       Feb 21, 2019
    @long2ice 已经找到实现方法了,跟服务的无关,是框架的机制。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2945 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 06:50 · PVG 14:50 · LAX 23:50 · JFK 02:50
    ♥ Do have faith in what you're doing.