As the title suggests I'm trying to use in the same application two different socket.io servers, one with socket.ioV4 and the other with socket.ioV2, the servers go up but I fail to get the sockets to connect.
A bit of context: the reason I'm trying to do this is because two clients need to exchange data using the Node.js application as a bridge, and each of them requires a different version of the socket.io package (as mentioned, V4 vs V2).
What I managed to do: I installed the V4 version as usual and the V2 version using an alias
npm install socket.io@^4.4.1
npm install socket.io-v2@npm:socket.io@2.0.1
and I created the two servers with
const express = require('express');
const http = require('http');
const { Server } = require('socket.io');
const app = express();
const server = http.createServer(app);
const io = new Server(server);
const v2_server = require('http').Server(app);
const iov2 = require('socket.io-v2')(v2_server);
The socket.io servers are defined as such
io.on('connection', (socket) => {
// DEBUG
console.log("V4 data received");
})
iov2.on('connection', (socket) => {
// DEBUG
console.log("V2 data received");
})
Then I spin up the two servers on two different ports
app.get("", (req, res)=>{
res.sendFile(__dirname + '/static/test.html')
})
server.listen(conn_port, () => {
console.log("V4 server started.")
})
v2_server.listen(v2_conn_port, () => {
console.log("V2 server started.")
})
and they do appear running as both logs are printed.
However, as I try to connect to the localhost on both ports, while I do see the html page provided, the socket.io connection doesn't seem to go through, as neither of the "Vx data received" logs appear (and buttons on the test page used to exchange data are unresponsive).
I'm pretty sure there might be a plethora of misplaced or misunderstood things here, as I'm just moving my first steps on node.js and web servers in general, so thanks in advance for the help and the patience!