Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

359
Views
socket.io-client connects with localhost but not with IP

I am struggling to find out the problem with connecting to server. With localhost, it's working fine, but when I am changing the host to IP address, it throws an error and what's strange for me, it adds /socket.io as a pathname.

'ws://134.122.32.44:8290/socket.io/?EIO=4&transport=websocket'

"socket.io-client": "^4.3.2", "socket.io": "^4.4.1",

This is a server config part.

 const { Server } = require("socket.io");
 this.socket = new Server(port, {
        cors: {
            origin: '*'
        }
    });

And this is the client config

this.socket = io(`ws://${wsHost}:${wsPort}`, {
  timeout: 15000,
  withCredentials: true,
  reconnectionDelayMax: 10000,
  transports: ['websocket', 'polling'],
});

If wsHost is localhost it is working fine, but not with an actual IP address. I am new to sockets and just want to find out where do I need to find the issue. Is it related to backend configs or client ?

UPDATED

const { Server } = require("socket.io");
 this.socket = new Server(port, {
        cors: {
            origin: '*'
        },
        path: "/api",
    });

And in client also.

this.socket = io(`ws://${wsHost}:${wsPort}`, {
  timeout: 15000,
  path: "/api",
  withCredentials: true,
  reconnectionDelayMax: 10000,
  transports: ['websocket', 'polling'],
});

Here is the Nginx server configs

server {
    listen 80;
    listen [::]:80;
    server_name _;
    access_log /var/log/nginx/api.access.log;
    error_log /var/log/nginx/api.error.log debug;
    location /api {
        proxy_pass http://134.122.32.44:7878;
    }
    location /var/www/ {
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection “upgrade”;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For 
        $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://134.122.32.44:8290;
    }
}

Error is here

websocket.js:50 WebSocket connection to 'ws://134.122.32.44:8290/api/?EIO=4&transport=websocket' failed:
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!