Skip to content

Instantly share code, notes, and snippets.

@anandtripathi5
Created March 3, 2022 23:10
Show Gist options
  • Save anandtripathi5/b1dc5ae2bff87c56c7850252814bbd35 to your computer and use it in GitHub Desktop.
Save anandtripathi5/b1dc5ae2bff87c56c7850252814bbd35 to your computer and use it in GitHub Desktop.
Websocket namespace
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