I am working on an Ionic 2 application. My use case is quite simple, I display a page, and I use the angular2's Http service to retrieve a string on a remote API, and I display this string on my page. Every seconds, I did the same "GET" request, and I display this string.
If I start my application with WiFi activated and connected to a network, every things works fine. Then when I disable WiFi, I except my HTTP Packets to be sent through mobile network, but my HTTP request never get out of my phone (I check in my backends logs, and I can't see any trace of them).
Of course, this problem doesn't occurs with my development phone (on Android 5.x), but only on my customer's phone (on Android 4.4)... I guess that the old android version can't switch the network interface of an already opened TCP connection.
Does some one have already experienced this kind of problem ? And is there some solutions I can develop in my app ?
Related
I have a chip with a WiFi module on it, which acts as an access point. What I'm trying to do is connect to the AP (which has no Internet access), send a POST request to a local address (http://192.168.4.1/address) and receive a response from the chip. I am writing an Android application, which is supposed to do that (and it does most of the time).
The problem is, I have a test device, which has this optimizing feature and checks if the WiFi network you're connected to has Internet access and if not, it uses mobile data automatically. I don't want that so I would want to either "force" the application to send it through the WiFi interface or find a workaround.
I use HttpURLConnection at the moment and it works like a charm if I turn off my mobile data. Otherwise it just waits and at the end triggers the timeout.
I have searched a lot about this issue and so far I have found nothing.
Since Android 5 (API 21), you can force connections to use the WiFi even if it's not the default network.
One solution is to find the corresponding network, for example with ConnectivityManager.getAllNetworks() and ConnectivityManager.getNetworkInfo():
Once you have the Network, you can either :
Open a connection on this network using Network.openConnection().
Bind the application to the network with ConnectivityManager.setProcessDefaultNetwork or ConnectivityManager.bindProcessToNetwork() (API 23+)
See Connecting your App to a Wi-Fi Device (especially Routing network requests) for more details.
Here is the deal... I have created a web service (asmx) which is running a long time consuming procedure in a class and returns the result. The web service is served in my local windows 10 IIS connected to the router with port forwarding. The android device connected to the same router (as the iis) accesses the web service in IIS with the outside IP (my router's IP on the internet - for checking purposes). I noticed that the first device accessing the service is served ok but the second delays big time to be served. Checking the net I found that there is a restriction in serving devices from the same IP. I disconnected one of the devices from the WLAN and everything worked as a charm. Both devices were served in the same time. How can I overcome this problem?
Thanks in advance
Searching the Internet I discovered (there are huge chances that I may be wrong) that this might have to do with the default behavior of DotNet framework which locks the session to the first in first served device:
ASP.NET application to serve multiple requests from a single process
and
Android http connection - multiple devices cannot connect the same server
I suppose that my IIS assumes that the attempt to hit the web service from the second device is another attempt by the same device. I also suppose that it assumes the device to be the same device since it is the same application with the same internal environment hitting the web service and it can't tell that they are two different devices. I tried to reproduce this error and check if I am right by hitting the IP reporting page in IIS from two different tabs of the Mozzila Developer edition browser but it works ok (so I am not sure if it is a session issue). I also found a report that the issue is present only in android devices but it was not clear enough if the server was IIS... The solution mentioned was "incorrect flag on the tcp kernel settings - Reuse connection". Does it tell anything to anyone of you?
If the session lock is indeed the problem is there a solution to make IIS distinguish that there are two devices indeed? Is there a setting in IIS that would change this default behavior of DotNet?
I am sure there is a solution (if indeed the issue is session lock) because I uploaded my code to an on-line server and it works perfect when hitting it from two Android devices. So either it is not a session lock issue or there is a setting that it changes this behavior of DotNet in IIS... Is anyone aware of such a setting?
I am working on an app that uses peer-to-peer communication between Android devices. It receives and delivers JSON data and the data never goes through the server ever. The server is only used to keep track of user IDs, login times, IP changes, and other stuff. This app will use sockets for communication.
Requirements
JSON data goes directly to an Android device from another Android device without going through server.
The android devices can be connected to any kind network like 3G or Wi-Fi (here I assume I have to use NAT).
Server is used to keep track of IP changes of the Android devices as they may be connected to any kind of network.
Challenges
The main problems I am facing are:
I don't know how to connect two devices if they are behind a Wi-Fi network.
What approach I can use if I am going to use P2P for delivering JSON data.
Update
For this I have to use hole punching. The idea I got is that no one can connect to a device from the outside. It must start communication from inside the device. So if A request server S for address of B, then server gives the address of B to A and vice versa. Now what? What occurs next?
Any suggestion would be greatly appreciated.
how can I execute HTTP requests or open a socket on Android Wear? I used to think that's impossible but the Web Browser for Android Wear app says the folloing:
"[..] works even when your phone is off if you have a smartwatch with Android Wear 5.1 and WiFi"*.
I tested it and that app CAN connect the internet when the paired phone is powered off.
Whenever I open a socket or try HTTP requests on Android Wear I always get a ConnectException saying failed to connect to http://foo.com (similar stack trace here). So I'm doing something different then that app is doing and I'd like to understand what that is.
Context: I'm working on proof-of-concept and just want to be able to execute HTTP requests and open sockets. I'd love to know if there's any way to do that. Even if it includes rooting the watch and doing some adb magic.
To clarify: I know about the Data Layer API and i'd still like to be able to just do HTTP requests and open sockets.
If your watch has Wifi and it is set up correctly, then you can make network calls on your watch when your watch is disconnected from the phone; when you connect to your phone via BT, wifi will be disabled. While it is enabled, you should be able to treat that as a usual network connectivity and make network calls. But keep in mind that if you write an app that relies on this, your app will fail to work when it gets connected to a phone so you need to handle that case and provide an alternative for your app to get the same data (i.e. using the phone's connectivity).
tl;dr How to find out from a server if Android device is online or not at any given time?
I have an app which needs an Internet connection at all times to make reservations. User can also make reservations independently, from a website.
However, if Internet connection on Android device is gone (edge case) - I would still like that device continues operate offline (and making reservations locally, offline) while website will stop accepting reservations - because Android device is no longer connected to an Internet and there could happen all kinds of sync errors.
In other words, Android device offline reservations have advantage over a website reservations.
So after Internet connection is retrieved on a device, website will continue operate properly.
Suggested solution
I thought about some solution which could include sending a push from a server to device and waiting for a response (HTTP call to some endpoint) in some reasonable time-period. If response doesn't come back - device is offline, otherwise it's online. Any other, more robust, suggestions?
There is nothing to do but use some Agent runs on Android and notifies the server that its on.
Other way, more complicated is to use "Push notification" (Meteor technology server side, for example).
Something about server side cron-job:
Stand alone process that run over all clients in data base, lets say every 1 day, and compares for each client last "im alive" meassage (request) with current time.
If difference equals lets say 1 week, sets client status to "Zombie".