Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
119
rated 0 times [  125] [ 6]  / answers: 1 / hits: 16315  / 3 Years ago, tue, october 5, 2021, 12:00:00

I am receiving an Error: xhr poll error in the connect_error event when trying to connect to my websocket gateway.
I am using "socket.io-client": "^4.2.0".


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

const ENDPOINT = "http://localhost:3001";

const socket = io(ENDPOINT);

socket.on("connect_error", (e: any) => {
console.log(e);
});

More From » reactjs

 Answers
5

You can try to set up the client connection to use only websocket transport. By default it is using weboscket and polling.


{
transports: ['websocket']
}

So your code will become:


const socket = io(ENDPOINT, {
transports: ['websocket']
});

[#50155] Wednesday, September 8, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
loganl

Total Points: 424
Total Questions: 86
Total Answers: 112

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
;