Socket.IO Connection Issue in Capacitor App

Hey Capacitor Community,

I hope you’re all doing well. I’m having a problem connecting my Capacitor app to a Socket.IO server at https://chat-dusky-rho.vercel.app/. I’ve tried for two days to fix it, but I can’t get the connection to work. I’ve checked the server, the URL, and made sure CORS is set up correctly.

If anyone knows about Socket.IO in Capacitor or has any advice, I’d really appreciate your help. Have you faced a similar issue? Your advice could really make a difference for me.

Thanks a lot!

Mohamad Salman

Here is the Code:

I don’t have any Socket.IO experience but I just tried via Postman and it is returning a 400. The URL Postman tries is https://chat-dusky-rho.vercel.app/socket.io/?EIO=4&transport=websocket when trying to connect to https://chat-dusky-rho.vercel.app. Seems like there is a miss-configuration on the server side.

Have you tried connecting outside of your Capacitor app to make sure your Socket.IO server is actually working?

Hello, thank you for your response. Yes, I tried outside of Capacitor, and that worked fine. However, when I am trying with Capacitor or Cordova, it’s just not working. I think something might not be working with Capacitor, and this could be related to the socket.io-client that Capacitor might not understand. However, I’ve seen that other people used similar code above, and it worked for them. Do I have to do
some other conifgurations in order this works in capacitor?

I have no idea but here are a few things that I can think of that you could try.

Do you by chance have CapacitorHttp enabled? If so, try with it disabled.

Does it work if you run your app just in the browser (as an SPA, not natively on a device)?

Hello everybody,
does anyone could implement socket.IO using capacitorJS?

I am currently trying but I get 400 “The client is using an unsupported version of the Socket.IO or Engine.IO protocols
but running same capacitorJS application on browser it works fine… how can server get 2 different versions of Socket.IO from same source?

When CapacitorHttp is enabled, it fails even before trying to establish a connection.
When is disabled, I get this ERROR 400… but anyway, I need capacitorHttp running, otherwise it breaks many other XHR requests on my application :frowning:

That’s so confusing… can’t understand why capacitorJS hasn’t a documentation page for such important resource!