Demo-Flask-SocketIO
Demo-Flask-SocketIO copied to clipboard
Text sent by server not displayed
Hi,
I have created a flask app as a server and am sending text from it to my client. I do not want any client interaction. The server must send a new message to the client as soon as that message is generated. I have adapted the code for my needs but my web page is blank.
Here is the code for my server.
from flask import Flask, request, render_template
from flask_socketio import SocketIO, emit
app = Flask(name)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
@app.route('/')
def index():
return render_template('index.html')
#@app.route('/display', methods=['GET'])
def display():
ut=request.args.get('spoken')
if ut is not None:
send_spoken(ut)
else:
return render_template('index.html')
@socketio.on('client connected') def handle_client_connection(message): print('Received message: ' + message) # for debugging purposes only # do something with message, e.g., you can say hello or simply log it somewhere
@socketio.on('spoken from client') def handle_spoken(spoken): print('received spoken: ' + spoken) # for debugging purposes only, see def send_spoken_to_client(spoken):
socketio.emit('spoken from server', spoken)
socketio.emit('message', {'data': spoken}, namespace='/signer')
if name == 'main':
app.run(host='0.0.0.0', port=15000, debug=True)
socketio.run(app, host='0.0.0.0', port=15000)
Here is my HTML code.