GithubHelp home page GithubHelp logo

Comments (13)

frnsys avatar frnsys commented on August 23, 2024

I'm just starting to use this library and I'm having the same issue. The client appears to connect without a problem, but if I try to do something like:

socketio = SocketIO(app)

// ...

socketio.emit('some event', broadcast=True)

None of the clients appear to receive the message.

from flask-socketio.

frnsys avatar frnsys commented on August 23, 2024

I've been doing some digging and it seems that the issue may be because socket.active_ns does not have the default namespace:
https://github.com/miguelgrinberg/Flask-SocketIO/blob/master/flask_socketio/__init__.py#L186

I'm looking through the gevent-socketio code to see where namespaces are added to that but direction would be appreciated.

from flask-socketio.

frnsys avatar frnsys commented on August 23, 2024

Quick update: I managed to get this working by sending a message on connect client side and then receiving it server side:

// Client side
$(function() {
    var socket = io.connect('http://localhost:5000');
    socket.on('connect', function() {
        socket.emit('connect');
    });
});
# Server side
@socketio.on('connect')
def on_connect():
    pass

Then using socketio.emit started working fine.

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on August 23, 2024

@mdgart Sorry, I seem to have missed your question from back a few months ago.

Have you resolved this problem? I would check if you are using the correct namespace. If you are using a namespace, this is implicit in the responses from inside a socket handler, but then when the server initiates there is no client context, so you have to specify the namespace. Hope this helps.

from flask-socketio.

mdgart avatar mdgart commented on August 23, 2024

Thanks for your answer, I resolved the problem.

from flask-socketio.

Dipen-D avatar Dipen-D commented on August 23, 2024

@mdgart , @miguelgrinberg : Look like I'm stuck with the similar question. Can anyone help me with this?

from flask-socketio.

wiwat-tharateeraparb avatar wiwat-tharateeraparb commented on August 23, 2024

+1 same issue here.

from flask-socketio.

MattSidor avatar MattSidor commented on August 23, 2024

@mdgart, it would be so great if you could share with everyone how you resolved the problem (if you can remember by now -- I know it's been a long time)

from flask-socketio.

sjoerdvan avatar sjoerdvan commented on August 23, 2024

I've been having this same problem. And I've partially solved it by adding a namespace to the emit. I send this from a seperate thread started by a client message. (See https://github.com/miguelgrinberg/Flask-SocketIO/blob/master/example/app.py for implementation details)

socketio.emit('message', {'Hello': "Goodbye"}, namespace="/test")

But I really want to call the function from another program and then send the message. This doesn't work (exact same code)
Any idea's?

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on August 23, 2024

@sjoerdvan did you set up a message queue so that your other script can pass on the emits to the server?

from flask-socketio.

sjoerdvan avatar sjoerdvan commented on August 23, 2024

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on August 23, 2024

@sjoerdvan well, you said your external script could not send emits. Maybe I misunderstood, seems you haven't done anything yet. Please check the docs for information on how to set up external scripts and you should be fine.

from flask-socketio.

sjoerdvan avatar sjoerdvan commented on August 23, 2024

@miguelgrinberg ah yes, I completely missed that part of the docs, I will look into it. Thanks!

from flask-socketio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.