Answer the question
In order to leave comments, you need to log in
What is the best way to connect to socket.io?
Goodnight.
// подключение проходит на ура и по ws
let chat = io.connect('http://domain.ru:33333', {transports: ['websocket', 'flashsocket', 'xhr-polling']}); // (1)
// подключение отваливается, потому что пытается юзать ws
let chat = io.connect('http://domain.ru', {transports: ['websocket', 'flashsocket', 'xhr-polling']}); // (2)
// подключение по ws отваливается, и начинает работать по xhr-polling
let chat = io.connect('http://domain.ru'); // (3)
#...
location /socket.io/ {
proxy_pass http://localhost:33333;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
#...
Answer the question
In order to leave comments, you need to log in
Nginx is configured correctly, here is how to set up the server side
https://www.npmjs.com/package/socket.io
Here as a client side
https://www.npmjs.com/package/socket.io-client
Non-standard ports no need to use.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question