0

I need someone to explain how I can get socketIO client to connect successfully with nodeJs app deployed to Google Cloud App Engine.

I setup nodejs clusters and so had to use socketIO's redis adapter to manage session affinity.

This has worked fine till I deployed to Gcloud App Engine.

Here is my current socketIO implementation on the server-side:

const { Server } = require("socket.io");
const redisAdapter = require("socket.io-redis");
const { setupMaster, setupWorker } = require("@socket.io/sticky");


const io = new Server(server, {
  pingTimeout: 60000,
  transports: ["websocket"],
  cors: {
    origin: "*",
    methods: ["GET", "POST", "DELETE", "PATCH"],
    allowedHeaders: ["Access-Control-Allow-Origin"],
    credentials: true,
  },
});
io.adapter(
     redisAdapter({
       host: process.env.REDISTOGO_URL,
       port: 15156,
       password: process.env.REDIS_PASSWORD,
     })
   );

setupWorker(io);
console.log("Redis socket Connected");

I am quite new to gcloud and so I will be very grateful for any help I can get. I have tried undoing the nodejs clusters but still doesn't work.

  • 1
    I don't know much about Socket.IO but I know that Google App Engine (Standard) does not support streaming or keeping a connection open infinitely so that messages are displayed bidirectionally (like instant messaging). You might want to try Google App Engine (Flex) for that or Google Compute Engine if that is what you need. – NoCommandLine Jun 01 '21 at 04:08
  • Thank you! I switched over to App Engine (Flex) and it worked! You are a life saver! However, I was sad to learn that it has no free tier. Wish me luck as I configure for lowest costs, as this is only a prototype app. – David Quartey Jun 01 '21 at 12:03
  • Look into Google Compute Engine. I think (not sure) they have free quota. You should also check to see if you can rearchitect your App so it will work on App Engine (standard). e.g. if you REALLY DON'T need instantaneous response, you could consider polling your server for messages at specific intervals in which case App Engine (standard) will work for you. If you decide to use App Engine (standard), check out our App at https://nocommandline.com All the best!! – NoCommandLine Jun 01 '21 at 16:21
  • I plan on switching to Compute Engine once I am ready to launch the product. – David Quartey Jun 04 '21 at 00:10

0 Answers0