推荐学习书目
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
gogobody
V2EX  ›  Python

请问 flask-socketio 如何向指定用户发送消息呢?

  •  
  •   gogobody · Nov 26, 2017 · 6793 views
    This topic created in 3113 days ago, the information mentioned may be changed or developed.

    我知道客户端在向服务器发送连接请求的时候 flask 可以获取 sid...然后怎么办呢....em..请教个各位大神!

    6 replies    2017-11-27 12:36:34 +08:00
    orFish
        1
    orFish  
       Nov 26, 2017
    在 server 端你得自己做一个客户端的 map 吧
    gogobody
        2
    gogobody  
    OP
       Nov 26, 2017 via Android
    @orFish 大神可不可以具体一点,小白有点懵逼...
    shyling
        3
    shyling  
       Nov 27, 2017
    连接时给他们 join(自己 userId) 的 room
    ImPerat0R
        4
    ImPerat0R  
       Nov 27, 2017 via Android
    记录用户连接时的 sessionid
    FingerLiu
        5
    FingerLiu  
       Nov 27, 2017
    自己在数据库(redis, mysql, mongodb)存一下 userId 和 sessionId 的绑定关系,然后
    socketio.emit("message", {'data': data}, room=sid])
    gogobody
        6
    gogobody  
    OP
       Nov 27, 2017 via Android
    @ImPerat0R @shyling @FingerLiu 感谢楼上的各位! emit(....,room=sid) 解决我的问题!👍
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2920 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 13:45 · PVG 21:45 · LAX 06:45 · JFK 09:45
    ♥ Do have faith in what you're doing.