0

I'm trying to connect a to a TCP server with an Android client. But when I try to connect (in debug) I always get the message that the socket is null.

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<application
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

MainActivity.java

boolean connection = false;
PrintWriter out;
BufferedReader in;
Socket client;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try
    {
        client = new Socket("xxx.xxx.xx.xx", xx);
        connection=true;
    }
    catch (Exception ex) {
        listItem.add("Could not connect");
        adapter.notifyDataSetChanged();
    }
}

0 Answers0