Hi Miguel,
I am using socket-io with flask to show incoming values on client. But the returned value is null. The server and client code are as follows:
from flask import Flask, render_template, jsonify, request
from flask_socketio import SocketIO, emit
app=Flask(__name__)
socketio = SocketIO(
app,
cors_allowed_origins="*")
values=[]
random_decimal=[]
@app.route('/')
def index():
return render_template('index.html')
@socketio.on('connect')
def on_connect():
value = request.args.get('test')
values.append(value)
random_decimal= str(values)
emit('after connect', {'data':random_decimal})
if __name__=='__main__':
socketio.run(app, debug=True)
====================================================
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SocketIO example</title>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//sending connect request to the server
var socket = io.connect('http://127.0.0.1:5000');
socket.on('after connect', function(msg){
console.log('after connect', msg);
$('#log').append('<br>'+ $('<div/>').text('Received: ' + msg.data).html());
});
});
</script>
</head>
<body>
<h1>SocketIO Example</h1>
<h2>Receive:</h2>
<div id="log"></div>
</body>
Hi Miguel,
I am using socket-io with flask to show incoming values on client. But the returned value is null. The server and client code are as follows:
====================================================