· 5 years ago · Nov 28, 2019, 05:46 PM
1from flask import Flask, render_template
2from flask_socketio import SocketIO, emit
3
4# https://flask-socketio.readthedocs.io/en/latest/
5# https://github.com/socketio/socket.io-client
6
7app = Flask(__name__)
8
9app.config[ 'SECRET_KEY' ] = 'jsbcfsbfjefebw237u3gdbdc'
10socketio = SocketIO( app )
11
12
13@app.route( '/' )
14def hello():
15 return render_template( './ChatApp.html' )
16
17def messageRecived():
18 print( 'message was received!!!' )
19
20@app.route('/receive/')
21def my_client():
22 return render_template('./hello.html')
23
24# @socketio.on('my event')
25# def receivedevent():
26# print("HELLO")
27
28@socketio.on( 'my event' )
29def handle_my_custom_event( json ):
30 print( 'recived my event: ' + str( json ) )
31 socketio.emit( 'my response', json, callback=messageRecived )
32
33if __name__ == '__main__':
34 socketio.run( app, host='0.0.0.0',debug = True )