title: Android java.net.SocketException: socket failed: EACCES (Permission denied)
body: <p>I'm trying to create a TCP/IP connection with a device that is running embedded linux, I'm using from android the USB tethering to have a ethernet connection between the Android device and the Embedded Linux device, I modified the embedded linux device to support RNDIS device driver.</p>
  
  <p>The Android and the embedded linux device are working correctly, a ethernet conection was established succesfully, I can ping from embedded linux to android device and viceversa.</p>
  
  <p>On my android application I created a simple service to establish a TCP/IP connection with the embedded linux device, the problem happens when I try to connect i got the following error:</p>
  
  <pre><code>02-17 13:53:13.300: E/TCP Client(2576): C: Connecting...
  02-17 13:53:13.310: E/TCP Client(2576): C: Error
  02-17 13:53:13.310: E/TCP Client(2576): java.net.SocketException: socket failed: EACCES (Permission denied)
  02-17 13:53:13.310: E/TCP Client(2576):     at libcore.io.IoBridge.socket(IoBridge.java:583)
  02-17 13:53:13.310: E/TCP Client(2576):     at java.net.PlainSocketImpl.create(PlainSocketImpl.java:201)
  02-17 13:53:13.310: E/TCP Client(2576):     at java.net.Socket.startupSocket(Socket.java:559)
  02-17 13:53:13.310: E/TCP Client(2576):     at java.net.Socket.&lt;init&gt;(Socket.java:225)
  02-17 13:53:13.310: E/TCP Client(2576):     at com.example.service.TCPClientThread.run(TCPClientThread.java:75)
  02-17 13:53:13.310: E/TCP Client(2576): Caused by: libcore.io.ErrnoException: socket failed: EACCES (Permission denied)
  02-17 13:53:13.310: E/TCP Client(2576):     at libcore.io.Posix.socket(Native Method)
  02-17 13:53:13.310: E/TCP Client(2576):     at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:181)
  02-17 13:53:13.310: E/TCP Client(2576):     at libcore.io.IoBridge.socket(IoBridge.java:568)
  02-17 13:53:13.310: E/TCP Client(2576):     ... 4 more
  </code></pre>
  
  <p>I have configured my manifest as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.dea600"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="14"
          android:targetSdkVersion="18" /&gt;
  
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt; 
      &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/example"
          android:label="@string/appName" &gt;
          &lt;activity
              android:name="com.example.gui.mainActivity"
              android:configChanges="orientation|screenSize"
              android:screenOrientation="landscape"
              android:theme="@android:style/Theme.Holo.Light.DarkActionBar" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
                  &lt;category android:name="android.intent.category.HOME" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;service
              android:name="com.example.service.TCPClientService"
              android:isolatedProcess="true"
              android:label="TCP Client Service"
              android:process=":TCPClientService" &gt;
          &lt;/service&gt;
  
          &lt;receiver
              android:name="com.example.service.TCPStartClientService"
              android:enabled="true"
              android:exported="true" 
              android:process=":StartTCPService"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  
       &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>The most extrange thing is if I use a Android VM (Genymotion) I'm able to connect and everithing works correctly, but when I try to use it on a real device I get the error.</p>
  
  <p>Thank you in advance for any comment.</p>
  
  <p>EDIT:</p>
  
  <p>This is the code I'm using to create the binding, I'm using the port 6540, and the IP is 192.168.42.130</p>
  
  <pre><code>public void run() {           
      try {             
          //here you must put your computer's IP address.             
          InetAddress serverAddr = InetAddress.getByName(SERVERIP);               
          Log.e("TCP Client", "C: Connecting...");
          //create a socket to make the connection with the server             
          Connection = new Socket(serverAddr, SERVERPORT);
          Log.e("TCP Client", "C: Connected...");
          // Output Stream
          OutStream = new DataOutputStream((OutputStream)Connection.getOutputStream());
          // Input stream
          InStream = new DataInputStream((InputStream)Connection.getInputStream());
  
          while (ThreadStatus) {
              try {
  
                  String message = myReadStream(InStream);
                  if (message.length() &gt; 0) {
                      Log.e("TCP Client", "Received message ... " + message);
                      if (mMessageListener != null){
                          mMessageListener.messageReceived(message);
                      }
                  }
              } catch (Exception e) {      
                  ThreadStatus = false;
                  Log.e("TCP Client", "S: Error", e);               
              }
          }
  
      } catch (Exception e) {               
          Log.e("TCP Client", "C: Error", e);           
      }  finally {                 
          try {
              Connection.close();
              OutStream.close();
              InStream.close();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      if (mConnectionEndListener != null){
          mConnectionEndListener.notifyConnectionEnd();
      }
  
  }       
  </code></pre>
  
  <p>I believe that when I try to create the socket the error occurs (<strong>Connection = new Socket(serverAddr, SERVERPORT);</strong>).</p>