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

635
Views
Socket.io-client connection error: websocket error

Previously, I was getting the output "xhr poll error" with the code:

import { io } from "socket.io-client";

const socket = io("https://socket.io/docs/v4", {
    reconnection: true,
    reconnectionDelay: 1000,
    reconnectionDelayMax: 5000,
    reconnectionAttempts: 3
});

socket.on('connect_error', function(error) {
    console.log(error.message);
});

With a bit of research, this was "resolved" by adding "transports: ['websocket']". Here's my current code:

import { io } from "socket.io-client";

const socket = io("https://socket.io/docs/v4", {
    reconnection: true,
    reconnectionDelay: 1000,
    reconnectionDelayMax: 5000,
    reconnectionAttempts: 3,
    transports: ['websocket']
});

socket.on('connect_error', function(error) {
    console.log(error.message);
});

Unfortunately, this doesn't really resolve my problem because now I get the following output: websocket error.

Other things I've tried: specifying the port after the URL and setting rejectUnauthorized to false. (both giving me the same websocket error.

I'm a bit stumped on what to do next, and it'd be nice to hear some of you guys' feedback!

Socket.io-client version: 4.5.1

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

By default, the client will try to establish a WebSocket connection if possible and will fall back on HTTP long polling if not, which explains why the first change you mentioned resolved the polling error, but now you have a websocket error.

If it's attempting to reconnect automatically, you might need to enable CORS or set credentials. If it's not, you should try manually reconnecting after a timeout with socket.connect()

about 4 years ago · Juan Pablo Isaza Report
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!