Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =========== app.py ====================
- from os import environ
- from flask import Flask, render_template
- from flask_socketio import SocketIO, emit
- app = Flask(__name__)
- app.config['SECRET_KEY'] = 'secret!'
- socketio = SocketIO(app)
- #Code here...
- if __name__ == '__main__':
- HOST = environ.get('SERVER_HOST', 'localhost')
- PORT = int(environ.get('SERVER_PORT', '5000'))
- socketio.run(app, host=HOST, port=PORT)
- ================== index.html ========================
- <!DOCTYPE html>
- <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.4.0/socket.io.js"></script>
- </head>
- <body>
- <h1>WebSockets with Flask</h1>
- <h2>Receive:</h2>
- <div id="log"></div>
- <form id="message" method="POST" action='#'>
- <input type="text" name="message_data" id="message_data" placeholder="Message">
- <input type="submit" value="send">
- </form>
- <script src="/static/index.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement