Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving Error: xhr poll error socket.io client React

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);
});
like image 506
Vladimir Vladimirov Avatar asked Mar 20 '26 02:03

Vladimir Vladimirov


2 Answers

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']
});
like image 98
Boris Mutafov Avatar answered Mar 21 '26 16:03

Boris Mutafov


set server.listen instead of

 app.listen
like image 38
mohammed kalash Avatar answered Mar 21 '26 15:03

mohammed kalash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!