Git Product home page Git Product logo

Comments (19)

abourget avatar abourget commented on August 20, 2024

Is this fixed ?

from gevent-socketio.

sontek avatar sontek commented on August 20, 2024

I will verify tonight

from gevent-socketio.

dswarbrick avatar dswarbrick commented on August 20, 2024

I've found that BaseNamespace.recv_connect() doesn't get called for the global namespace, but does get called on specific endpoints. Conversely, I also noticed that the "connect" event never fires on the client if an endpoint name is used, but does fire if no endpoint name is specified.

from gevent-socketio.

eoranged avatar eoranged commented on August 20, 2024

Is it any progress on the issue?

from gevent-socketio.

eoranged avatar eoranged commented on August 20, 2024

Tested master branch: both recv_connect and recv_disconnect doesn't work for me.
I use code like the following and see only "called" message, but no "connected" or "disconnected":

class MainNamespace(namespace.BaseNamespace):

    def on_my_init(self, data):
        print "called"

    def recv_connect(self):
        print "connected"

    def recv_disconnect(self):
        print "disconnected"

And attaching using this namespace in request handler this way (stolen from cross_origin example, request is the Werkzeug's Request object):

socketio_manage(request.environ, {'': MainNamespace}, request=request)

And, yes. I'm connecting to server, calling my_init method, waiting a bit and then closing browser tab.

from gevent-socketio.

abourget avatar abourget commented on August 20, 2024

Yeah, there is ambiguity here. The "recv_connect" call is received only when we receive a CONNECT packet.. On the "global namespace", the empty string that is, no such packet is sent.. because the opening of the connection is itself the "connect" event. Instead, on the global namespace, we should implement the "connect(self)" method.

Same thing goes for disconnect. There is a disconnect packet that can be sent to close an endpoint (or namespace), but it is not sent for the global namespace.

So there might be a solution: we could remove recv_connect(self), and recv_disconnect(self), and call in both cases (even though they are different events) "connect(self, type)" and "disconnect(self, type)".. where 'type' would be what triggered the event. I know it's not very nice.. or maybe we should just update the documentation ? Or maybe we should discourage the usage of the global namespace, as it is there mostly for backwards compatibility.

What do you think ?

from gevent-socketio.

eoranged avatar eoranged commented on August 20, 2024

30.05.2012, 22:35, "Alexandre Bourget" [email protected]:

Yeah, there is ambiguity here.  The "recv_connect" call is received only when we receive a CONNECT packet..  On the "global namespace", the empty string that is, no such packet is sent.. because the opening of the connection is itself the "connect" event.  Instead, on the global namespace, we should implement the "connect(self)" method.

Same thing goes for disconnect.  There is a disconnect packet that can be sent to close an endpoint (or namespace), but it is not sent for the global namespace.

Thanks, I understand the problem now.

So there might be a solution: we could remove recv_connect(self), and recv_disconnect(self), and call in both cases (even though they are different events) "connect(self, type)" and "disconnect(self, type)".. where 'type' would be what triggered the event.  I know it's not very nice.. or maybe we should just update the documentation ?  Or maybe we should discourage the usage of the global namespace, as it is there mostly for backwards compatibility.

What do you think ?

I wonder how does it work with node.js implementation (it actually works!). I suppose the best way is to choose the same or similar solution.

Handlers "connect(self, type)" and "disconnect(self, type)" looks like a spike for me, because it negates all advantages of RPC.

Also, It will be nice to mention in documentation that recv_* functions doesn't work for global namespace.


Reply to this email directly or view it on GitHub:
#9 (comment)

Best regards,
Vladimir Protasov.

from gevent-socketio.

eoranged avatar eoranged commented on August 20, 2024

Okay, I've got deeper into docs and now I see that global namespace is supported only in 0.6.

So, I think it will be enough to mention in documentation for recv_* functions that it doesn't supported for global namespace.

Best regards,
Vladimir Protasov.

from gevent-socketio.

dswarbrick avatar dswarbrick commented on August 20, 2024

It seems that the Python code and JS code are at odds with one another. For example, I have some JS code as follows:

var global_socket = io.connect();
var socket = io.connect("/console");

// "connecting" event fires for specific namespaces
socket.on("connecting", function (transport_type) {
    $("#state").text("connecting to " + transport_type + "...");
});

// Note global_socket, as "connect" event does not fire for specific namespaces
global_socket.on("connect", function () {
    $("#state").text("connected");
});

But then on the Python side of things:

class ConsoleNamespace(BaseNamespace):

    def recv_connect(self):
        # Spawn custom method upon Socket.IO client-namespace connect
        self.spawn(self.listener)

    def listener(self):
        while True:
            # Do custom background stuff
            gevent.sleep()

The recv_connect() is called upon 'socket = io.connect("/console")' (routed to the ConsoleNamespace by socketio_manage()), which spawns my custom class method (which lurks in the background, monitoring a TCP socket and occasionally emit()'ing packets to the Socket.IO client connection).

However, if I didn't have the explicit no-namespace "global_socket = io.connect()" in the JS, then I'm not able to determine on the client when it has successfully connected.

I'm open to any suggestions on how to more gracefully handle this.

from gevent-socketio.

sontek avatar sontek commented on August 20, 2024

We need to handle this how the node.js implementation does. I assume since their client is only firing the packet on named namespaces, their server probably doesn't do anything different than we are currently doing.

We should make a node.js sample app that tests this.

from gevent-socketio.

dswarbrick avatar dswarbrick commented on August 20, 2024

Whilst searching for answers about this, I stumbled across this page http://sideeffect.kr:8005/
If you scroll down a little way to the namespace example, it looks like node.js will send a "connect" event when using a namespace... which would seem to indicate that gevent-socketio needs to do that also.

from gevent-socketio.

abourget avatar abourget commented on August 20, 2024

Oh, so when we create the namespace, we should ourselves send a 'connect'
packet to the browser ?

On Tue, Jun 26, 2012 at 5:16 PM, Daniel Swarbrick <
[email protected]

wrote:

Whilst searching for answers about this, I stumbled across this page
http://sideeffect.kr:8005/
If you scroll down a little way to the namespace example, it looks like
node.js will send a "connect" event when using a namespace... which would
seem to indicate that gevent-socketio needs to do that also.


Reply to this email directly or view it on GitHub:
#9 (comment)

from gevent-socketio.

sontek avatar sontek commented on August 20, 2024

fixed on 0df3e5c

from gevent-socketio.

dswarbrick avatar dswarbrick commented on August 20, 2024

Sorry, I think this is still not working correctly. The "connect" event still does not fire on the client when connecting to a namespaced endpoint. For example:

socket = io.connect("/foo");

// This never fires
socket.on("connect", function () {
    alert("connected");
});

I don't want to fire some user-connect event, when somebody joins a chat room. I want to know when the socket.io endpoint has successfully connected. This (I thought) is the purpose of the "connect" event firing.

I can get a "connect" event to fire if I use a non-namespaced endpoint.

from gevent-socketio.

dswarbrick avatar dswarbrick commented on August 20, 2024

Also, I noticed while testing, that if I add recv_disconnect() Python method to my namespace, it is being called repeatedly if the page has been refreshed... I'm not sure if this expected behaviour or not.

from gevent-socketio.

sontek avatar sontek commented on August 20, 2024

If you define a recv_disconnect() you need to call self.disconnect() yourself. (Thinking about ways to make that cleaner), that is why you are getting the repeat.

I'll fix the connect so that it fires properly.

from gevent-socketio.

sontek avatar sontek commented on August 20, 2024

Fixed in e039720

from gevent-socketio.

dswarbrick avatar dswarbrick commented on August 20, 2024

@sontek Thanks, that finally fixed it :)

from gevent-socketio.

vivekhub avatar vivekhub commented on August 20, 2024

@dswarbrick that is nice.. our kludge goes away as well

from gevent-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.