repl.it
Python

No description

fork
loading
Files
  • main.py
  • console.txt
  • session.html
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# import os
# os.system("pip install flask")
# os.system("pip install flask-socketio")

import os
from flask import Flask, render_template
from flask_socketio import SocketIO

app = Flask(__name__,root_path='/home/runner',static_folder='.')
app.config['SECRET_KEY'] = 'vnkdjnfjknfl1232#'
socketio = SocketIO(app)

@app.route('/')
def sessions():
    return render_template("session.html")

def messageReceived(methods=['GET', 'POST']):
    print('message was received!!!')

@socketio.on('my event')
def handle_my_custom_event(json, methods=['GET', 'POST']):
    print('received my event: ' + str(json))
    socketio.emit('my response', json, callback=messageReceived)

if __name__ == '__main__':
    socketio.run(app,host='0.0.0.0', port='8080',debug=True)