0

I run a chat portal built in NodeJS and React that is hosted on a Azure App Service. Recently with a lot more people using it we have been instructed by Microsoft to scale out the app essentially giving it more instances.

While this does fix the performance issues, the Socket.IO component of the portal then stops working as expected. It seems to only receive pings from Socket.IO once and a while which leads to the data not refreshing when it needs to. I have Websockets and ARR Affinity enabled on the app service, disabling ARR Affinity breaks the Socket.io functionality entirely. I am new to running NodeJS on multiple instances with Socket.IO so I would appreciate any feedback from the community on how to resolve this issue.

The Socket.IO is configured as followed:

Server index.js

const server = require('http').createServer(app);
const io = require('socket.io')(server);

app.io = io;

Client Side

import { io } from "socket.io-client";

const socket = io(null, {
    reconnectionDelayMax: 3000,
    reconnection: true,
    reconnectionAttempts: Number.MAX_VALUE,
    timeout: 7000
});

export default socket;

1 Answers1

0

As per the Socket IO documentation, you're using the correct syntax with version 3.x

// ES6 import or TypeScript  
import { io } from "socket.io-client";  
// CommonJS  
const io = require("socket.io-client");  

Try in the old way for using SocketIO on the client-side, first import it via:

import * as io from 'socket.io-client';  

Then, probably in a constructor, establish a connection to the server's IP and Port running the SocketIO server.

Here import * as io, which means that you want to import the entire module - an object that includes the default and named exported members, and you want to refer to this object as io.

Refer Link1 & Link2 for more information

Delliganesh Sevanesan
  • 4,146
  • 1
  • 5
  • 15