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

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

  •  
  •   gogobody · 2017-11-26 23:10:13 +08:00 · 5951 次点击
    这是一个创建于 2314 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    6 条回复    2017-11-27 12:36:34 +08:00
    orFish
        1
    orFish  
       2017-11-26 23:40:19 +08:00
    在 server 端你得自己做一个客户端的 map 吧
    gogobody
        2
    gogobody  
    OP
       2017-11-26 23:49:33 +08:00 via Android
    @orFish 大神可不可以具体一点,小白有点懵逼...
    shyling
        3
    shyling  
       2017-11-27 01:46:17 +08:00
    连接时给他们 join(自己 userId) 的 room
    ImPerat0R
        4
    ImPerat0R  
       2017-11-27 08:40:29 +08:00 via Android
    记录用户连接时的 sessionid
    FingerLiu
        5
    FingerLiu  
       2017-11-27 09:32:01 +08:00
    自己在数据库(redis, mysql, mongodb)存一下 userId 和 sessionId 的绑定关系,然后
    socketio.emit("message", {'data': data}, room=sid])
    gogobody
        6
    gogobody  
    OP
       2017-11-27 12:36:34 +08:00 via Android
    @ImPerat0R @shyling @FingerLiu 感谢楼上的各位! emit(....,room=sid) 解决我的问题!👍
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5219 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 07:22 · PVG 15:22 · LAX 00:22 · JFK 03:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.