When trying to connect to a socket with an Android client, I receive ECONNREFUSED ConnectException.

When I run the code on my PC, it works fine I am able to connect to the remote server (raspberry pi, haskell) without an issue (so we can exclude that possibility).

Relevant code from ConnectionManager.class (Error thrown in line s=connect):

```
    @Override
    protected void onHandleIntent(Intent intent) {
    try {
        s=connect();
        socket_out = new PrintWriter(s.getOutputStream(), true);
        socket_in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

```

The connect function (error thrown in line "return new socket")

```
    private Socket connect() {
    try {
        return new Socket("Thereisarealip in here",Realport);
    } catch (IOException ex) {
        Logger.getLogger(ConnectionManager.class.getName()).log(Level.SEVERE, null, ex);
    }
    throw new RuntimeException();
}

```

XML Permissions include the following

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

```

The ConnectionManager Java class is called from the mainthread using:

```
    Intent intent = new Intent(this, ConnectionManager.class);
    startService(intent);

```