Flask-SocketIO提出了错误的请求

时间:2019-05-10 19:43:14

标签: javascript python sockets flask

我有一个Flask应用程序,我在其中使用SocketIO进行聊天,但似乎无法向服务器提出适当的请求。

建立连接后,一切正常

@socketio.on('connected')
def on_connect(json):
print(json)
print(f'client established a connection.. with ip: 
{request.remote_addr}')

但是每当我发送一条消息时,请求就会等待,然后它返回一个错误的请求

@socketio.on('send message')
def handle_custom_vent(json):
print('received event ' + str(json))
res = make_test_obj()
socketio.emit('my response', res, 
callback=message_received(res, json))

它早些时候运行良好,但是现在这个问题突然出现了。

here is the bad request

我正在使用JavaScript库发出套接字请求。

import io from 'socket.io-client'
....
   this.socket = io('http://localhost:5000/')


  //works fine
  this.socket.emit('connected', {
    msg: 'hello'
  })


 //holds and gives bad request
 this.socket.on('my response', (message) =>{
    this.setState({
      messages: [...this.state.messages, message]
    }, () => console.log('message received was ', message) )
  })
}

0 个答案:

没有答案