flask websockets code example

Example 1: Flask socket io

pip install flask-socketio

Example 2: websockets socketio flask

<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>

Example 3: flask socketio with gevent

$ uwsgi --http :5000 --gevent 1000 --http-websockets --master --wsgi-file app.py --callable app