title: Can't use ServerSocket on Android
body: <p>I'm trying to listen on a port using <code>ServerSocket</code> on an Android device. I want to be able to connect to this port over WiFi using a computer on the same network.</p>
  
  <p>I get no exception when binding it to a port, however when I check netstat it says:</p>
  
  <pre><code>Proto Recv-Q Send-Q Local Address           Foreign Address         State
  tcp        0      0 (null):4040             (null):*                LISTEN
  </code></pre>
  
  <p>I've tried countless ways of binding it to localhost, 0.0.0.0, the WiFi LAN IP address of the device with <code>SocketInetAddress</code> and <code>InetAddress.getByName</code>. Nothing seems to work.</p>
  
  <p>When I try to connect to the port from a computer in the same WiFi (I've tried both netcat and Java's <code>Socket.connect()</code>), all I can see in Wireshark is an ARP request:</p>
  
  <pre><code>Who has [phone's LAN address]? Tell [computer LAN address].
  </code></pre>
  
  <p>This request repeat itself until timed out.</p>
  
  <p>I've tried the reverse way, by setting the ServerSocket on the computer and connecting to that port from the phone, that works very well.</p>
  
  <p>My testing phone is an Samsung Spica i5700 with a custom ROM.</p>
  
  <p>Any ideas?</p>
  
  <p>Edit:
  The code is simple as this:</p>
  
  <pre><code>ServerSocket server = new ServerSocket();
  server.setReuseAddr(true);
  server.setTimeout(0);
  server.bind(new InetSocketAddress(4040));
  
  Socket client = null;
  while((client = server.accept()) == null);
  // Connected
  enter code here
  enter code here
  </code></pre>