Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using namespace socket inside namespace class #183

Open
skyguy126 opened this issue May 3, 2018 · 2 comments
Open

Using namespace socket inside namespace class #183

skyguy126 opened this issue May 3, 2018 · 2 comments

Comments

@skyguy126
Copy link

I am creating a socket connection as follows:

class ClientNamespace(BaseNamespace):

    def on_connect(self):
        logger.info("connected")
        clientSocket.emit("descriptor", "some cool data")

    def on_disconnect(self):
        logger.info("disconnected")

    def on_reconnect(self):
        logger.info("reconnected")

socketIO = SocketIO('127.0.0.1/sock', 80, Namespace=ClientNamespace)
clientSocket = socketIO.define(ClientNamespace, '/clients')
socketIO.wait() # listen forever

The issue is that the script immediately crashes as it says clientSocket is not defined when on_connect is called. I believe this is due to the fact that the define method instiantates the class before setting clientSocket to the namespace socket.

If I use socketIO.emit(. . .) inside ClientNamespace the server (nodejs socket.io 1.x) never receives any events in /clients which is what I need it to do. Am I doing something wrong or are there any workarounds?

@Hendrikto
Copy link

I think you can just use self.emit. Does that solve your problem?

@skyguy126
Copy link
Author

@Hendrikto I will try again maybe I did something else before....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants