Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shrutisharma2891 opened this issue Mar 30, 2023 · 3 comments
Labels

Comments

@shrutisharma2891
Copy link

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

@maarteNNNN
Copy link
Member

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

@shrutisharma2891
Copy link
Author

shrutisharma2891 commented Mar 30, 2023

@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()

@maarteNNNN
Copy link
Member

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

@MegaGM MegaGM added the invalid label Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants