socketIO-client
socketIO-client copied to clipboard
Using namespace socket inside namespace class
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?
I think you can just use self.emit. Does that solve your problem?
@Hendrikto I will try again maybe I did something else before....