SocketIO: test

This commit is contained in:
Petr Kracik 2020-06-05 16:14:56 +02:00
parent 3563b19073
commit ce4842d93e
3 changed files with 34 additions and 0 deletions

1
runsockettest.sh Executable file
View File

@ -0,0 +1 @@
uwsgi --http :8001 --gevent 1000 --http-websockets --master --wsgi-file socketiotest.py --callable app

19
socketiotest.py Normal file
View File

@ -0,0 +1,19 @@
from flask import Flask, render_template
from flask_socketio import SocketIO
app = Flask(__name__)
socketio = SocketIO(app)
@app.route("/")
def index():
return render_template("socketio.html")
@socketio.on('my event')
def handle_my_custom_event(json):
print('received json: ' + str(json))
if __name__ == '__main__':
socketio.run(host="0.0.0.0", port=8001, app=app)

14
templates/socketio.html Normal file
View File

@ -0,0 +1,14 @@
<html>
<body>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>
<script type="text/javascript" charset="utf-8">
var socket = io();
socket.on('connect', function() {
socket.emit('my event', {data: 'I\'m connected!'});
});
</script>
ahoj3
<input type="button" onClick="socket.emit('my event', 'test');" value="test" />
</body>
</html>