Connecting to socket server from an external app

Hi! I’m creating a mobile app with React Native. The last piece that’s missing for me is connecting to socket events from my Wappler web app.

Is it possible to connect the react native app to the socket.io server made with Wappler, with the socket-client library?

Socket.io-client’s documentation says:

From a different domain

In case your front is not served from the same domain as your server, you have to pass the URL of your server.

const socket = io("https://server-domain.c

Does that mean that I can simply enter the domain where my Wappler web app is hosted, and it will subscribe to events?

Yes, but then it’s up to you to make your app work with the data structure Wappler uses for events (console.log comes to the rescue!)

1 Like

Thanks for answering as always.

I assume that I need to allow the connection IP from the server side somehow right? Otherwise everyone would be able to use the domain to subscribe for the data :stuck_out_tongue: Is that then related to cors?

Hm? You were planning to whitelist every IP address of your mobile user? :wink:

CORS applies to browsers, don’t know if it applies to React Native - you’d have to test this and see if the developer console comes up with a CORS error.

No problem :slight_smile:

1 Like

:sweat_smile:

So anyone can in theory connect to my socket server for events? For now it doesn’t really matter for my use case as it’s not data sensitive, but I wonder how this is solved when this needs to be secured

Anyone that can access your website can access your socket server for events. I don’t know how or if Wappler has any sort of authentication for this, or if the events themselves contain sensitive data or just tell stuff like “reload this server connect called sc_chat”

Also, CORS doesn’t prevent someone from sneaking in your events, it only prevents another website from connecting to your website events