flask-socketio

Python Flask SocketIO broadcasting outside of @socketio context

被刻印的时光 ゝ 提交于 2019-12-24 02:13:04
问题 I'm trying to send a broadcast when an outside value changes. Camonitor calls the callback when the value changes, and I want to notify all connected clients that the value has changed and they need to refresh. from flask import Flask from epics import caget, caput, camonitor from flask_socketio import SocketIO, emit app = Flask(__name__) socketio = SocketIO(app) @socketio.on('connect') def local_client_connect(): print "Client connected" def update_image_data(pvname, value, **kw): #

Flask-socketio context for Flask-SQLAlchemy

给你一囗甜甜゛ 提交于 2019-12-24 01:30:15
问题 I am creating a live reporting application using Flask, Flask-Socketio and Flask-SQLAlchemy. My current design creates a background thread on connection which querys an API and inserts into the applications data. However, when running this, I get the error RuntimeError: No application found. Either work inside a view function or push an application context. flask_react_app.py: from threading import Lock from flask import Blueprint, render_template from .model import Stock from . import

Heroku sock=backend Server Request Interrupted for a Flask SocketIO application

我与影子孤独终老i 提交于 2019-12-23 10:51:29
问题 I have a flask-socketio app hosted on heroku with the following Procfile : web: gunicorn --worker-class eventlet hello:app Ever since I switched to socketio, the app has been behaving inconsistenly. Earlier the app would run for a while and then POST requests would start timing out. Since yesterday night, I keep getting the error sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/js/third-party/browser.js" host=deard.herokuapp.com request_id=725da6af

Angular single page app and socketio multiple sockets

≡放荡痞女 提交于 2019-12-23 05:25:40
问题 I have yet to find a solution or any information on this topic. Basically I am developing a chat app with flask, socketio, and angularjs. I created a single page app with angularjs so when I click for example a register button this page comes into view even though it is not actually routing to a new page. The problem is when I click the register button or switch views another socket connection gets created. So when I go back to the chat app view to send a message it sends 3 messages because 3

Using Flask-socketio and the socketIO client

混江龙づ霸主 提交于 2019-12-22 08:08:11
问题 I'm currently trying to understand how sockets work. I'm using Flask-socketio and a python socketio client and running through a basic example. Here is what I have done so far app.py from flask import Flask, render_template from flask_socketio import SocketIO, emit app = Flask(__name__) app.config['SECRET_KEY'] = 'secret!' socketio = SocketIO(app) @socketio.on('aaa') def test_connect(): print("Welcome, aaa received") emit('aaa_response', {'data': 'Server'}) if __name__ == '__main__': socketio

RuntimeError: working outside of request context

不问归期 提交于 2019-12-12 10:38:21
问题 I am trying to create a 'keepalive' websocket thread to send an emit every 10 seconds to the browser once someone connects to the page but getting an error and not sure how to get around it. Any idea how to make this work. And how would i kill this thread once a 'disconnect' is sent? Thanks! @socketio.on('connect', namespace='/endpoint') def test_connect(): emit('my response', {'data': '<br>Client thinks i\'m connected'}) def background_thread(): """Example of how to send server generated

How to share variables between socket handlers?

99封情书 提交于 2019-12-12 03:44:45
问题 Is there a way to give multiple socket handlers access to the same variable? Below is a bit of pseudo code showing what I'd like to achieve, but I'm getting an UnboundLocalVariable exception for shared_variable . shared_variable = None @socketio.on('initialize') def initialize_variable(data): shared_variable = data @socketio.on('print') def print_variable(): print str(shared_variable) Any thoughts? Thanks in advance! 回答1: If you want to use a global variable, you have to declare it as such in

Integrate Flask-JSGlue on a socketized Flask-SocketIO application

核能气质少年 提交于 2019-12-11 19:17:29
问题 Case 1 Suppose you have a Python Flask application and you want to socketize it - you do the standard: app = Flask("MyApp") socketio = SocketIO(app) Case 2 Suppose you have a Python Flask application and you want to integrate Flask-JSGlue - https://pypi.org/project/Flask-JSGlue/ - you do the standard: jsglue = JSGlue() app = Flask("MyApp") jsglue.init_app(app) Case 3 (Question) Suppose now you want to integrate Flask-JSGlue on a socketized app - how would you go with this? I'm trying to

change route and send message using socketio but socketio is working

。_饼干妹妹 提交于 2019-12-11 15:39:41
问题 <!DOCTYPE html> <html> <head> <title>Login</title> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.6/socket.io.min.js"></script> <script> document.addEventListener('DOMContentLoaded',()=>{ var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port); socket.on('connect',()=>{ console.log('connected'); document.querySelector('#submit').onclick =() =>{ const user= document.querySelector('#user').value; const room = document

Problems with receiving 'utf-8' from client

送分小仙女□ 提交于 2019-12-11 13:23:01
问题 I am trying to create a 2-way communication between server and client using Flask and socket.io . Everything works fine until server receives utf-8 string from client, which gets garbled. Sending from server to client works fine, and prior to sending from client to server, the client prints the message correctly. Here is some code that reproduces the problem: app.py: import flask from flask_socketio import SocketIO, emit, disconnect import json app = flask.Flask(__name__) socket_io = SocketIO