How to access server instance from inside an event handler
See original GitHub issue` server = SIOServer()
@server.service.on('get_bananas', namespace="/namespace1")
async def some_request_1(sid=None, data=None):
#server.service.enter_room(sid, f'user__{sid}')
print(f'EMITING server_response WITH SID {sid} and namespace /namespace1')
await server.service.emit('server_response', {}, namespace='/namespace1')
# BUT server IS NOT DEFINED ?????
#server.service.leave_room(sid, f'user__{sid}')
server.start_service()
async_to_sync(server.service.emit)('server_response', {}, namespace='/namespace1')
`
I’m trying to respond from the server by emitting something inside the event handler. That means client-says-something ----> triggers-event-in-server ----> server-emits-to-all
But I am unable to access the server instance from inside the handler. How can I get access to it ? Is there any special variable ? I’ve been unable to find a suitable example for this.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Access object instance inside an event handler - Stack Overflow
I have a DOM structure with a couple of <input type="text" /> elements. I need to write a couple of methods to enhance...
Read more >Event handling (overview) - Event reference - MDN Web Docs
You can use the Event reference to find out what JavaScript objects fire events for particular APIs, e.g. animation, media, and so on....
Read more >Integration Services (SSIS) Event Handlers - Microsoft Learn
In the Event handler list, select the event handler you want to build. Click the link on the design surface of the Event...
Read more >Event handling - discord.js Guide
In most cases, you can access your client instance in other files by obtaining it from one of the other discord.js structures, e.g....
Read more >Handling and dispatching events with Node.js - LogRocket Blog
Learn how to create, dispatch, and manage events in Node.js. ... http, Allows you to create a http server and handle data transfer...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The error is on this line:
This is a problem with your client, not your server. You created a sync client, and then are trying to use it as if it was an asyncio client.
I don’t know how I missed that. Thank you!