Created
March 16, 2022 06:28
-
-
Save basavyr/fa3376a734f5df48b1bd6cc801383a21 to your computer and use it in GitHub Desktop.
quick flask-socketIO server app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# general imports | |
from flask_socketio import SocketIO | |
from flask_socketio import emit | |
from flask import Flask, render_template | |
from random import random | |
import time | |
from threading import Thread, Event | |
from threading import Lock | |
# define the port and host that the app will run on | |
PORT = 5051 | |
HOST = '127.0.0.1' | |
# Set this variable to "threading", "eventlet" or "gevent" to test the | |
# different async modes, or leave it set to None for the application to choose | |
# the best option based on installed packages. | |
# source of the doc => https://github.com/miguelgrinberg/Flask-SocketIO/blob/main/example/app.py | |
async_mode = None | |
thread = None | |
thread_lock = Lock() | |
# define the flask app | |
app = Flask(__name__) | |
app.config['SECRET_KEY'] = 'secret!' | |
app.config['DEBUG'] = True | |
# define the socketio object | |
socketio = SocketIO(app, async_mode=async_mode) | |
def main(): | |
socketio.run(app, port=PORT, host=HOST) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment