Created
March 3, 2022 23:10
-
-
Save anandtripathi5/b1dc5ae2bff87c56c7850252814bbd35 to your computer and use it in GitHub Desktop.
Websocket namespace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask_socketio import emit | |
from extensions import db | |
from base import BaseSocket | |
class Foo(BaseSocket): | |
def on_get_foo_details(self, **kwargs): | |
try: | |
# Do something useful like print statement | |
print("Hello! Awesome world") | |
# Then send a event back to the world | |
emit("event_name", dict(random_key="random_value"), namespace=self.namespace) | |
# or | |
emit("event_name", dict(random_key="random_value")) | |
except Exception as e: | |
print("Catch the exception") | |
# Db session remove is important | |
db.session.remove() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment