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!
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)?