Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to define a slot on socket connected #18

Open
sabahath786 opened this issue Oct 13, 2020 · 0 comments
Open

how to define a slot on socket connected #18

sabahath786 opened this issue Oct 13, 2020 · 0 comments
Labels

Comments

@sabahath786
Copy link

sabahath786 commented Oct 13, 2020

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():

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

@Sliim Sliim added the question label Jul 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants