Permanent connection via Wi-Fi and 3G in Android

I have little doubt about the network connection procedure in Android.

My scenario is similar, I am connecting to a remote server via TCP using 3G. After he connected, I turned on Wi-Fi. Android switched to WiFi. And, still a live connection to the server means there is no connection.

Here I want to know one thing. When N / W switches from 3G to Wi-Fi, will the Android (or any other) device change its IP address? and if he changes his IP address, will this previous connection be valid? (This means that a new connection should appear on the new IP address again.)

Thanks in advance.

+3
source share
1 answer

, IP- . WiFi, IP-. , Android IP- ( ), , - "" IP-. , , , , :) , Android , IP-. WiFi, IP- Wifi.

, :

  • Android 3G
  • Android HTTP GET -
  • Android WiFi 3G

GET .

:

  • : 3 ( , 3 ), try-catch-repeat, .
  • , :

    if(!isOnline()) {
      Log.e("OFFLINEERROR", "No Network Connectivity");
    }
    
    public boolean isOnline() {
      try {
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        return cm.getActiveNetworkInfo().isConnectedOrConnecting();         
      } catch(Exception e) {
        //Returned a null so no Internet connection!
        return false;
      }
    }
    
  • ( , , ).

, .

+2

Source: https://habr.com/ru/post/1747286/


All Articles