A
A
ArthurHlushko2022-04-03 02:50:11
Angular
ArthurHlushko, 2022-04-03 02:50:11

How to setup socket.io for live server?

On localhost, sockets work fine, there are no problems, but on a live server there are always errors. For a couple of days I can’t fix this problem in any way, I will be very glad if there is a solution.
6248defce993c040171789.png

If you leave only polling in transports, then there are no errors, in network everything returns with the status "ok", but it still does not work.

server:

const app = require('express')();
const server = require('http').Server(app);
const io = require("socket.io")(server, {
  cors: {
    origin: "*",
    methods: ["GET", "POST"],
    transports: ['websocket', 'polling'],
    credentials: true
  },
  allowEIO3: true,
});
const port = process.env.PORT || 3000;
server.listen(port, () => {
  console.log('socket.io, port:', port);
})

client:
public socket = io('https://bichatgo.demo-app.live', {
  transports: ['websocket', 'polling']
});

Versions of socket.io and socket.io-client = 4.4.1

For localhost, this is the client:
public socket = io('http://localhost:3000', {
  transports: ['websocket', 'polling']
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2022-04-03
@karabanov

Does the lack of a port bother you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question