简体   繁体   English

在 Google App Engine 上部署 socket.io

[英]Deploying socket.io on Google App Engine

How can I deploy and run socket.io server written in Node.js on App Engine.如何在 App Engine 上部署和运行用 Node.js 编写的 socket.io 服务器。 Is it supported?是否支持? If not what alternatives can I use如果不是,我可以使用哪些替代方案

Here is my socket:这是我的插座:

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');
});

Yes this is now possible as of Jan 2019 with Google App Engine Flex.是的,现在可以使用 Google App Engine Flex 从 2019 年 1 月开始。 You can read more about it here .您可以在此处阅读更多相关信息。 It even has all the code you need.它甚至拥有您需要的所有代码。

tldr; tldr; you need to use GAE flex and add the below to your app.yaml:您需要使用 GAE flex 并将以下内容添加到您的 app.yaml 中:

network:
  session_affinity: true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM