You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from flask import Flask
from flask_socketio import SocketIO, emit
from common.signals import on_heartbeat_data_received_signal
class FlaskApp():
def __init__(self,config_path):
self.logger = Logger.get_instance("FlaskApp")
self.logger.debug("started")
# Create an application
app = Flask(__name__)
app.config['SECRET_KEY'] = 'gjr39dkjn344_!67#' #todo read from yaml
socketio.init_app(app, async_mode="threading", cors_allowed_origins="*")
CORS(app)
# load yml to read flask configuration from config path
with open(config_path, "r") as yamlStream:
try:
self.flask_config = yaml.safe_load(yamlStream)["flask"]
except yaml.YAMLError as exc:
print("replace to logger")
self.logger.info(self.flask_config["host"])
self.logger.info(self.flask_config["port"])
self.logger.debug("connect to signal to send to UI..")
on_heartbeat_data_received_signal.connect(self.publish_data)
socketio.run(app, debug=True, host=self.flask_config["host"], port=self.flask_config["port"])
self.logger.debug("flask server is up....")
self.logger.debug("ended")
@socketio.on("connect")
def websocket_connect():
print("websocket connected...")
# socketio.emit("response", "mesg from server") # this line is working
#registered slot to capture data from signal
def publish_data(self, data, **kwargs):
self.logger.debug("started publish data to connected websocket client..")
self.logger.debug(data)
try:
socketio.emit("response-data", data) #this is not emiting data
except Exception as e:
self.logger.error(e)
@socketio.on("response-data")
def handle_message(message):
print(message)
`
websocket_connect is emiting the data, push registered slot is not emiting data, how to register a slot on same socket thread
The text was updated successfully, but these errors were encountered:
I am using flask-socketio, to publish the data to client after connecting signal to the slot,
signals.py
import signalslot
on_heartbeat_data_received_signal = signalslot.Signal()
message.py
import signals.py
on_heartbeat_data_received_signal .emit(data="hello")
main.py
class Main():
flaskApp()
if name == "main":
main = Main()
flaskApp.py
from flask import Flask
from flask_socketio import SocketIO, emit
from common.signals import on_heartbeat_data_received_signal
class FlaskApp():
`
websocket_connect is emiting the data, push registered slot is not emiting data, how to register a slot on same socket thread
The text was updated successfully, but these errors were encountered: