I am hitting otp api's from Emulator its work but if I am using real device then getting failed to http connecting error found.
2020-11-06 13:33:23.603 24840-24840/a3.amp35.in E/Genrate: failed to connect to /192.168.132.101 (port 80) from /26.81.35.26 (port 39596) after 100000ms
need help
Your device is outside of your local network. Api is on 192.168.132.101 while device is out given net 26.81.35.26
Either expose your API to the outside world (eg. port forward it or host in on globally accessible device) or connect your device to your local network (eg, use the same WIFI, or via VPN)
Also firewall settings on the 192.168.132.101 might block the incoming connections from different subnets.
And probably many more possible causes...
Related
I have an Android App and an IoT device where the connectivity and the communication will be through Wi-Fi. The IoT device will provide an hotspot (without Internet) so that we can connect our Mobile Wi-Fi with that device hotspot. After connecting the Mobile with Wi-Fi, when we open the app, the app will try to find the device using TCP socket connection to connect and communicate to the IoT device.
The App works fine and communicates with the device successfully. But the problem here is, the connection and communication is not happening if the Mobile Data is turned ON. The app works only with the Mobile Data turned OFF.
I guess the App is searching for the IoT device through Mobile Data since the Mobile data has an active internet connection and the Wi-Fi does not. I want the App to look for the IoT device only through Wi-Fi even if Mobile Data is ON.
I have a similar App in React Native which has the same functionality and had the same problem. I fixed it with using react-native-tcp-socket package which has an option to make the app search through a particular interface (which has the options wifi, ethernet and cellular).
Both the Apps have an hardcoded IP Address for connecting to the IoT device. This works only when Mobile Data is turned Off. In the React Native App, I fixed it using that package mentioned previously with the Dynamic IP address by getting it from the WifiManager. When I tried the same with the Android App it did not work.
I looked into the package's native code and tried to replicate the same, but getting the below error:
java.net.ConnectException: failed to connect to /192.168.1.2 (port 6378) from /:: (port 39495): connect failed: ECONNREFUSED (Connection refused)
Caused by: android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
Any Suggestions?
Is any other way of implementation possible to achieve the output?
The solution is to bind the socket to the Wi-Fi network. We must create a listener and get the Network from the listener's result.
So, Whenever we open or reopen a socket we must bind that socket to Wi-Fi network. This is what I was missing. After adding this, it worked fine.
network.bindSocket(socket);
And, another update is, in my case, The dynamic IP address didn't work but the pre-defined hardcoded IP address works and I am unable to find the reason, unlike my previous case which was vice-versa.
I'm coding an app which consist of two pieces. Desktop and android. There is one desktop and several android devices. (don't know the count.) I want to communicate android devices between desktop with TCP. However, android devices doesn't know desktop's lan ip address.
I thouht 2 ways:
1-Desktop app changes the local ip address on start. So android devices know the ip address. (I coded with that ip address)
2-Desktop app always tries to connect ip addresses (192.168.0.1 - 192.168.0.255) to sent desktop's ip address. And when an android device connect to the network accept the connection then know desktop's ip.
But there is some problems in both ways.
On first, you must be administrator to changing lan ip. So run command as admin with java is a problem. Because if I do this, when user start the program, uac always asks for it.
On second, I think there will be performance issues because of app always tries to connect. Exept this, when android device connect and dhcp gives it 192.168.0.5 , but loop is on 192.168.0.150. So android device have to wait for connection.
Is there a better way than these?
Look at this post Network discovery in Java using multicasting
I think this would be the best way to do it.
The server will listen for a broadcast message from client
the client sends a broadcast request asking for server ip
server receives request and replies back with server ip.
You can use the hostname. If the network is properly configured, the host name will point to the correct ip even if it changes
I am following this tutorial to implement this: http://www.veereshr.com/Android/AndroidToServlet
I got my server up and running and I am able to open its localhost link in my browser. However, when I run the Android app on my Nexus 5, I get this error:
11-26 01:34:46.501 1092-1340/com.example.nav.wificlient D/Exception:java.net.ConnectException: failed to connect to /10.0.2.2 (port 8080): connect failed: EHOSTUNREACH (No route to host)
11-26 01:35:29.171 1092-1557/com.example.nav.wificlient D/Exception: java.net.ConnectException: failed to connect to /10.0.2.2 (port 8080): connect failed: ETIMEDOUT (Connection timed out)
Both my laptop (which is running the server program) and my phone are connected to the same network (called eduroam) on a college campus. I made sure that my firewall settings are not blocking incoming connections on my laptop.
I'm wondering if maybe the campus network settings are blocking this somehow...but I'm not sure. Any ideas on how I can narrow down what may be going wrong?
10.0.2.2 is a unique address directly interpreted by the emulator to reference the machine running the emulator. This is useful as "localhost" would simply reference the emulator itself.
As you are not running your android application on an emulator, but rather an actual device, you need to change your application so that, instead of connecting to 10.0.2.2, it connects to the local IP of the computer hosting the server.
See here for more information.
I need to connect an android device to my java program via socket connection. The device is working as server. The problem is that while trying out socket connection I need to give IP address and port number of server.
Is there something like a static IP address for an Android device to connect? If not, is there any alternative way to establish a socket connection between the device and my program?
As the device has to have a connection to the same network as the computer, it has to have an IP address configured. So you have to use that one.
The used port is defined by the server application running on your device.
If you have the problem that anyhow a normal network connection is not possible, but you have an ADB connection, you can forward local pots to the device and let your server listen:
http://developer.android.com/tools/help/adb.html#forwardports
Over a mobile connection (GPRS, EDGE, UMTS, HSDPA) there will be no practicable way to establish a connection from somewhere to your device (instead you have to do it the other way, while canceling the whole client-server directive), in cause of the used IP sharing. In that case you have a problem of which I'm not aware if it's possible in general, not to mention how you could achieve this.
Otherwise you simply have to configure a static IP for your device when connected to your local network, or you have to evaluate the actual IP of your device every most of the time, while using it with this configuration:
Resolve it by the device itself
Resolve InetAdress from DhcpInfo
Documentation for DhcpInfo
Resolve by using ADB command
How can I check if my Android application is able to connect to a certain host? For example, I can make a HTTP GET call from a company web service if I am connected to the company network. If I am not on the company network (router, etc.) I can't make the HTTP GET call and it says "Unable to resolve host : No address associated with hostname". How do I check if the wifi or data is within the company?
That error means you don't have an IP related to the domain you want to surf. There is something wrong with DNS.
Try to use nslookup to check your connection with host you want to visit and then check if HTTP GET returns error.