Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Socket.io How to Connect to Local Node Server from Device

I'm making a connection when pointing the io.connect() method towards my localhost in the iOS simulator, so everything is working there.

But when the connect() method is pointed towards my machine's LAN IP address I am unable to successfully connect to the server neither in the simulator or on the device..

I'm pretty stumped on this one right now, any help would be appreciated thanks.

like image 820
camwhite Avatar asked Jan 28 '16 04:01

camwhite


1 Answers

Solved by tunneling localhost:3000 via ngrok and allowing an exception domain.

In your info.plist you need the following under App Transport Security Settings

enter image description here

On a mac command line run

  • brew cask install ngrok
  • ngrok http 3000

Then grab the outputted ngrok.io URL and use it in your io.connect() call and you should be set.

like image 172
camwhite Avatar answered Sep 17 '22 22:09

camwhite