N
N
nurdus2017-09-21 02:11:50
Nginx
nurdus, 2017-09-21 02:11:50

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)

Everywhere they write that the problem is in crooked proxy servers.
I have the following nginx settings:
#...
location /socket.io/ {       
    proxy_pass http://localhost:33333;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";        
}
#...

Is the problem mine or somewhere on the side (and nothing can be done about it)?
(1) the option suits me perfectly, BUT sometimes non-standard ports are closed and then the client will not be able to connect ... can this be somehow bypassed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Mukovoz, 2017-09-21
@castomi

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 question

Ask a Question

731 491 924 answers to any question