How to adapt APP that uses TCP protocol to 3g connection?

4

I'm developing an APP for Android and I used direct TCP connection as well as HTTP requests.

For the perfect functioning of my application being connected on a 3g network instead of WiFi, do I need to modify my code? Or is the 3g connection managed by the Android operating system?

How does the 3g connection send and receive TCP / IP packets to an internet-connected server? How exactly does it work?

    
asked by anonymous 25.10.2014 / 09:54

1 answer

5

At the application level, we usually do not have to worry about the type of data connection that is available on the device.

The operating system is the one who has this concern and management.

Responding directly to your question:
No, you do not have to modify your code, everything should work correctly.

Concern about having application

In the application, we have to worry about checking if there is any connection to enable and / or perform operations that require it:

Permissions

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Verification example

With these permissions we can consult on the device, which status the connection:

public void myClickHandler(View view) {
    ...
    ConnectivityManager connMgr = (ConnectivityManager) 
        getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        // Temos ligação, continuar
    } else {
        // Não temos ligação, informar utilizador
    }

    // ...
}

This example and others can be consulted and analyzed in detail on the documentation page for:

Connecting to the Network | Android Developers (English)

TCP / IP over 3G

TCP / IP is present in devices that have the GPRS service that is available in mobile technologies from the 2nd Generation.

Because a supported and TCP / IP-enabled device receives at least one IP address, communication from it is the same as communication on any PC or server connected to the Internet.

Related reading:

Note: The particularities of the operation of all these services and protocols are already outside the scope of this website, so I will not elaborate on this in more detail.

    
25.10.2014 / 13:18