This is my first experience with socket. My project stack: NextJS(v10), express, socket.io, socket.io-client, freeice
Everything works fine on localhost. The problem arose when I decided to test on a test server(started project with PM2).
server.ts
const nextApp = next({ dev: config.dev });
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);
io.on('connection', socket => console.log('connected')); // did not write the rest of the code here, because I don't even get the console.log
on client side
import { io } from 'socket.io-client';
const options = {
'force_new_connection': true,
reconnectionAttempts: 'Infinity',
timeout: 10000,
transports: ['websocket']
};
const socket = io('http s://mysite.com:3000', options);
what i get in a short time:
WebSocket connection to '' failed: WebSocket is closed before the connection is established.
The first and probably the most banal question due to my inexperience is whether I should configure anything on the Amazon server itself (probably said nonsense) and whether it can somehow have an impact PM2?
Second, here const server = require('http').Server(app);. It is problem?
I checked, I don't call close() anywhere, it happens here:
Thanks for any help
I found another small difference between a local test and a site test. I am getting two different objects. What is lt?
const socket = io(connectionUrl, options);
console.log('socket: ', socket);