I'm trying to serve files from a React-Native app. Im using react-native-tcp module but when I create a TCP server it isn't on a nmap output over the mobile device ip address. I've tried with an external client with nodejs but I get ECONNREFUSED. At the same time, If I try with a client inside the react-native app and an external server, I get the same result.
I don't know if there's a protection or the module doesn't work properly. I've also the android.permission.INTERNET in the manifest.
Related
I'm building a mobile app in React with Ionic and Capacitor.
I'm running a local server with a local API built with Strapi (a headless CMS) that is running on localhost:9000.
I'm having a hell of a time trying to connect my local API to my Ionic app on an Android emulator. The connection works fine on a development server on a web browser. My emulator can also access my local API on a web browser. My app, however, cannot connect to the API when it is running on an emulator.
Here's how I have proceeded so far:
in the .env file of my ionic-react app, I have set the URI to my local API. I have replaced "localhost" with my IP address :
REACT_APP_API_URL = "http://192.168.1.31:9000"
in the gradle.properties file of my app, I have added proxy settings:
systemProp.http.proxyHost=192.168.1.31
systemProp.http.proxyPort=9000
systemProp.https.proxyHost=192.168.1.31
systemProp.https.proxyPort=9000
in the AndroidManifest.xml file of my app, I have added two permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Observations:
(✔️) When I run ionic serve to launch a development server in a browser on my local machine, the HTTP requests execute fine. I can fetch my data.
(❌) When I run the app in Android Studio on an emulator, the HTTP requests fail ("Type Error : fetch failed").
(✔️) Yet, when I open a web browser on the aforementioned emulator and try to access my API on 192.168.1.31:9000/api/games, I get a valid response.
The emulator can access my local API, but my app running on the emulator, cannot. It baffles me. Does anyone have an idea what I'm doing wrong?
I have tried replacing my IP address with 10.0.2.2 in the config files, with no success.
From left to right:
my app in a web browser,
my app on an emulator (with an empty carousel because the HTTP request failed),
a web browser on the emulator trying to access the API and getting a valid response.
I'm trying to create an Android app with Ionic to send messages to a Node.js server. I'm using socket.io#2.3.0 for the server and socket.io-client#2.3.0 for the Ionic app. The Ionic app is supposed to open a socket.io connection with the server, then send the message "Hello, World!". The Ionic app build for the web works properly, I tried running it from other devices (my laptop and my phone) and in both cases the socket.io connection worked and the server printed out the message received from the Ionic app.
// Server output
Server running on port 5000.
New connection from 7rI7qvo9gNjVD5ElAAAA
Hello, World!
But when I build the Ionic app for Android using the commands:
ionic cap add android
ionic cap open android
And then debug from Android Studio, the app launches, but I don't see any message from the server, and I don't even see an error message in the Android Studio debug tab.
// Server output
Server running on port 5000.
At first I thought this was a network problem so I made sure the AndroidManifest.xml file included the permissions INTERNET and ACCESS_NETWORK_STATE, I tried building an APK and running it on my phone, but it still doesn't work so I don't know what I should do.
I'm using the version 5.4.16 of Ionic.
Thanks for reading this, have a nice day :)
I fixed this issue by hosting the Node.js server on Heroku, now everything works fine, I'm not sure why though. Since the protocol changes from http to https when I host the server on Heroku, I'm guessing Android doesn't like the http protocol.
In my Android emulator, I was able to contact the GAE dev server.
I use this url: "http://10.0.2.2:8080/myurl".
The server is listening on http://127.0.0.1:8080.
Then, after I've updated the emulator to the Nexus 5X version with Google Play(API 27), the connection fails and the server show this log:
ERROR 2018-01-11 11:17:05,463 wsgi_server.py:329] Request Host 10.0.2.2 not whitelisted. Enabled hosts are set(['127.0.0.1'])
I'm using the latest GAE python SDK with webapp2.
Any idea on how to solve the problem?
The more recent versions of the development server includes whitelisting checks of the source IP address of incoming requests.
You can use the --enable_host_checking=False command line option for the GAE devserver, which disables these checks. Not a good idea if you're running on an untrusted network.
You're probably seeing such errors even for accessing the devserver from the same machine. Another option for these requests would be to use the --host 10.0.2.2 devserver option (i.e. use your machine's external IP address instead of localhost/127.0.0.1, but that won't help with the emulator requests if you're running the emulator on some other machine.
Ideally the whitelist should IMHO be manageable independently from the server's IP address, but this is what is available presently.
I have created a hybrid mobile app using ionic 2. The app can connect to a Django-powered website on a localhost through Rest API when using "ionic serve" command (using web browser on my end device).
Now, I want to use the app using Bluestacks as emulator. The Django website and the API (running on the localhost) can be accessed through the browser app of the bluestacks. Here were the steps I performed to do this one:
Installed allow-control-allow-origin to enable cross origin information sharing on Google Chrome on my local device.
I have added ALLOWED_HOSTS = ['10.0.2.2'] in my django settings.
Access the django website through Bluestacks' browser using
http://10.0.2.2:8000/
However, the mobile app emulated in Bluestacks could not access the API. Any solution to this problem?
The django conf look's OK.
With this kind of problem, in general, i use tools like :
localtunnel (free)
ngrok
to acces to my localhost from everywhere
example with lt :
$ lt -p 8000 -s andynionic
your url is: https://andynionic.localtunnel.me
You must also add andynionic.localtunnel.me to the Django config
ALLOWED_HOSTS = ['10.0.2.2', 'andynionic.localtunnel.me']
with hibrid, you probably do CORS request, see also cors-django
hope it's help
I followed this tutorial to setup a cloud database for my Android App
https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints
Everything compiled fine and the server is running at http://localhost:8080/
However I keep getting this error
failed to connect to /10.0.0.2(port 8080) after 20000ms
I tried replacing 10.0.0.2 with my local IP address but it didn't work and showed the same error.
I am using Android Studio and debugging the app on my Android phone. Kindly help. Thanks!
Couple of areas to check:
Make sure you can connect to your locally running server using local IP address. In in your computer browser go to :8080. If it doesn't work then make sure your Run/Debug Config in AS is calling 127.0.0.1 or 0.0.0.0 address.
your android app has to be calling your pc's local IP address.
You need to start the dev server listening on 0.0.0.0. By default, the dev server listens only on localhost which means requests from other devices will not work. Just edit your run configuration and set the server address.
First find the IP Address of your machine (e.g., 192.168.x.x), by using ifconfig.
Change your build.gradle file of the endpoints project by adding this code appengine.run.host='192.168.x.x' at the end of the file.
Change the address in your android code with .setRootUrl("http://192.168.x.x:8080/_ah/api")