'Socket.IO : connect_error event not emitted
i have a simple socket.IO server, and a client that connects to it :
socket = io('http://localhost:' + port + '/chat', {
reconnection: false,
query: {
name: username
}
})
it works perfectly fine, but when i tried implementing the behavior of that client when the server cannot be found (which i simply test by just loading the page without starting the server), i faced a simple issue : the connect_error
event is not emitter. Right after i initialize the socket, i have this code :
socket.on('connect_error', ()=>{
console.log("Error! ")
})
as i said, this callback is never called, i get an error message in the console stating that the request returned 404 (http://localhost:5454/socket.io/?name=AA&EIO=4&transport=polling&t=O2__7JM
), but my custom error message is never printed.
So, what am i doing wrong ? Isn't this event supposed to be fired if the connection with the server couldn't be established ? If not, how do i handle this situation (i.e. how do i make socket.io call a certain callback if the connection failed ?)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|