D
D
Dmitry2017-07-22 20:17:35
Nginx
Dmitry, 2017-07-22 20:17:35

Why doesn't websocket want to work over cellular?

There is an application that uses a websocket connection (SockJS -> Nginx -> Tornado).
I observe strange behavior. The connection works fine if the laptop or phone is connected to Wi-Fi, but if you disconnect from Wi-Fi and use cellular, then the data from the server does not come.
At first I thought it was because of http, where either the headers could be cut off. Ok! Changed everything to https - did not help.
Nginx version 1.12.1;
Nginx config:

upstream ws_video {
    ip_hash;

    server 127.0.0.1:9101;
    server 127.0.0.1:9102;
    server 127.0.0.1:9103;
    server 127.0.0.1:9104;
}


server {
    listen      443;

    server_name ____.ru;

    ssl         on;
    ssl_certificate      /home/admin/conf/web/ssl.____.ru.pem;
    ssl_certificate_key  /home/admin/conf/web/ssl.____.ru.key;

    location / {
        proxy_pass http://ws_video;
        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

2 answer(s)
N
Night, 2017-07-22
@maxtm

Look in the browser console to see what the server is responding to.
Try to connect "directly" (curl, telnet) on a cellular connection and see what happens.
From the theory of delirium: try another cellular connection.

D
Dmitry, 2017-07-23
@pyHammer

All the problem was in the upstream! I removed it completely and added proxy_pass http://127.0.0.1:9101; and everything began to work. Also, the tornado launched not 4 workers, but one.
The Tornado also served as an annunciator. When the event happened, I did a POST to myself "requests.post(" https://____.ru/notify ", params=dict(message=string))" tornado processed it

from notification.connection import ClientConnection

class BroadcastHandler(tornado.web.RequestHandler):
    def post(self):
        message = self.get_argument('message', default="")
        
        for client in ClientConnection.clients:
            data = json.loads(message)

            if data['dev'] in client.devices:
                client.send(message)

        self.write(str(ClientConnection.clients))

When I worked via Wi-Fi tornago, something returned here "self.write(str(ClientConnection.clients))", but when I connected via mobile data, this line did not contain a single connection ...
I wonder what if I did with POST a request to https://____.ru/notify on my computer, then no matter what network I work on, everything worked ...
The problem was gone, but I still didn’t understand what its essence was.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question