invisibleroads / invisibleroads/socketIO-client
Using namespace socket inside namespace class
- Dominant language
- Python
- Stars
- 441
- Forks
- 204
- PR merge metrics
- No merged PRs in 30d
Description
I am creating a socket connection as follows:
```python
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?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.