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

Asked

Viewed 499 times

4

I am developing an APP for Android and used direct TCP connection and also HTTP requests.

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

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

1 answer

5


At the application level, we usually don’t have to worry about what kind of data connection is available on the device.

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

By directly answering your question:
No, you don’t have to modify your code, everything should work correctly.


Concern for implementation

In the application, we have to worry yes, to check if there is any connection to allow and/ or perform operations that require:

Permissions

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

Example of verification

With these permissions we can consult on the device, which state 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 GPRS service that in turn is available in mobile communications technologies from 2nd Generation.

Since a device with TCP/IP support and use receives at least one IP address, communication from it is equal to communication on any PC or server connected to the Internet.

Related reading:

Note: The particularities about the operation of all these services and protocols is already outside the scope of this site, so I will not elaborate more on the subject in this reply.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.