当我在本地部署flask socket io时,我在客户端中收到消息。 但是当我尝试在Google Cloud实例(ubuntu)中进行部署时 我什么都没得到。
服务器:
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
@socketio.on('message')
def handle_message(message):
send('Hello World')
if __name__ == '__main__':
socketio.run(app, debug = True)
#socketio.run(app, host='0.0.0.0', port=80)
客户端:
$(document).ready(function() {
var socket = io.connect('http://127.0.0.1:5000');
socket.on('connect', function() {
socket.send('User has connected!');
});
socket.on('message', function(msg) {
$("#messages").append('<li>'+msg+'</li>');
console.log('Received message');
});
$('#sendbutton').on('click', function() {
socket.send($('#myMessage').val());
$('#myMessage').val('');
});
});
然后我尝试:
服务器:
socketio.run(app, host='0.0.0.0', port=80)
客户端:
var socket = io.connect('http://<instance external ip>:80');