在 Google App Engine 上部署 socket.io



如何在 App Engine 上部署和运行用 Node.js 编写 socket.io 服务器。是否受支持?如果不是,我可以使用哪些替代方案

这是我的套接字:

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
console.log('a user connected');
socket.on('disconnect', function(){
console.log('user disconnected');
});
socket.on('subscribe', function(room) {
console.log('joining room', room);
socket.join(room);
});
socket.on('send message', function(data) {
console.log('sending room post', data.room);
socket.broadcast.to(data.room).emit('conversation private post', data.message)
});
});

http.listen(3000, function(){
console.log('listening on *:3000');
});

是的,从2019年1月起,使用Google App Engine Flex现在可以做到这一点。您可以在此处阅读有关它的更多信息。它甚至拥有您需要的所有代码。

您需要使用 GAE flex 并将以下内容添加到您的 app.yaml 中:

network:
session_affinity: true

相关内容

最新更新