socketcluster icon indicating copy to clipboard operation
socketcluster copied to clipboard

BadConnectionError - socketcluster-client when requesting from server side. It works fine if the request is issued from the browser.

Open shrutisharma2891 opened this issue 2 years ago • 3 comments

I have a service that attempts to create a lock on an object and then perform some operations. The process works completely fine when the request is issued from the browser but when trying to do it via server it is failing.

The error that I can see is "BadConnectionError"

socketcluster-client: 16.0.4 socketcluster-server: 16.1.0

shrutisharma2891 avatar Mar 30 '23 17:03 shrutisharma2891

I'd need a code example to understand what you're trying to do. Could you provide a minimal example?

maarteNNNN avatar Mar 30 '23 17:03 maarteNNNN

@maarteNNNN Just trying to create a client socket and then connect it.. it seems that it is never able to open the connection and times out. Its running on nginx - could that be an issue ?

let clientSocket = scClient.create({ "hostname": "[server].com", "port": 820, "secure": true, "rejectUnauthorized": false }) clientSocket.connect()

shrutisharma2891 avatar Mar 30 '23 19:03 shrutisharma2891

Via a nginx reverso proxy you might have some problems because it needs additional settings for WebSockets. An example:

server {
        listen 80;
        listen [::]:80;
        server_name <domain>;
        location / {
                # Reverse proxy
                proxy_pass http://localhost:8000;
                # Send original IP from client to app
                proxy_set_header X-Real-IP $remote_addr;
                # Needed for websockets use
                #proxy_buffering off;
                #proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }
}

On the client you need to make sure the url points to that domain, and if it has SSL use:

const client = socketclusterClient.create({
  hostname: '<domain',
  port: 443,
  secure: true,
})

See the docs

maarteNNNN avatar Apr 04 '23 13:04 maarteNNNN