【问题标题】:Restarting Supervisor and effect on FlaskSocketIO重启 Supervisor 和对 FlaskSocketIO 的影响
【发布时间】:2015-10-02 14:16:46
【问题描述】:

在我的index.html (HTML/Javascript) 我有:

$(document).ready(function(){
        namespace = '/test'; 

        var socket = io.connect('http://' + document.domain + ':' + location.port + namespace);

        socket.on('connect', function() {
            socket.emit('join', {room: 'venue_1'}); 
        });       


        socket.on('my response', function(msg) {
            $('#log').append('<br>Received #' + ': ' + msg.data);
        });       
    });

在我的Server 我有:

@socketio.on('connect', namespace='/test')
def test_connect():
    if session.get('venue_id'):
        emit('my response', {'data': 'Connected'})      
        session.pop('venue_id', None)
    else:
        request.namespace.disconnect() 

@socketio.on('join', namespace='/test')
def join(message):
    join_room(message['room'])
    room = message['room']  
    emit('my response', {'data': 'Entered the room ' + message['room']})

登录后,我设置session['venue_id'] = True并移动到index.html。我得到的输出是:

Received #: Connected
Received #: Entered the room venue_1

我的问题:初始运行后,我保持index.html 页面打开,然后通过supervisor 保持stopstart 我的项目。此时为什么我得到与上面相同的输出?我会认为在initial connect 之后,venue_id 会从session 中删除,因此会调用request.namespace.disconnect()

有人可以向我解释一下这里的事件顺序吗?

谢谢

【问题讨论】:

    标签: javascript python flask flask-socketio


    【解决方案1】:

    Socket.IO 客户端内置了重新连接逻辑。如果服务器消失了,就会出现预期的断开连接,但客户端立即开始重新连接,并且显然很快就成功了,因为重新启动的停机时间非常短.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-09
      • 2011-04-16
      • 1970-01-01
      • 2015-12-20
      • 2011-01-16
      • 2016-10-17
      • 2011-05-18
      • 2013-09-05
      相关资源
      最近更新 更多