Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Network Programming: IOExceptions and StackOverflowError
    text
    copied!<p>In my Android app, I try to connect to a port on a local server to get some packets. I've encased to code in some try &amp; catch's but with the following code:</p> <pre><code>address = "192.168.175.82"; public void run() { try { smtpSocket = new Socket(address, 60001); os = new DataOutputStream(smtpSocket.getOutputStream()); is = new DataInputStream(smtpSocket.getInputStream()); } catch (UnknownHostException e) { System.err.println("Don't know about host: " + address); run(); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to: " + address); run(); } catch (Exception e) { System.out.println("retry"); run(); } </code></pre> <p>if ther server is not on, I obviously get the IOException a few times (e.g. a few hundred times) before I get a stack overflow error and the app crashes.</p> <pre><code>01-20 22:21:32.526: ERROR/AndroidRuntime(5678): java.lang.StackOverflowError 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at java.util.Hashtable.get(Hashtable.java:282) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at java.util.Properties.getProperty(Properties.java:177) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at java.lang.System.getProperty(System.java:440) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at java.lang.System.getProperty(System.java:412) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at java.lang.Boolean.getBoolean(Boolean.java:174) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at org.apache.harmony.luni.net.NetUtil$Action.run(NetUtil.java:89) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at org.apache.harmony.luni.net.NetUtil$Action.run(NetUtil.java:80) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at java.security.AccessController.doPrivilegedImpl(AccessController.java:264) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at java.security.AccessController.doPrivileged(AccessController.java:84) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at org.apache.harmony.luni.net.NetUtil.preferIPv6Addresses(NetUtil.java:51) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at org.apache.harmony.luni.net.PlainSocketImpl.bind(PlainSocketImpl.java:190) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at java.net.Socket.startupSocket(Socket.java:777) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at java.net.Socket.tryAllAddresses(Socket.java:192) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at java.net.Socket.&lt;init&gt;(Socket.java:256) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at java.net.Socket.&lt;init&gt;(Socket.java:220) 01-20 22:21:32.526: ERROR/AndroidRuntime(5678): at com.example.sockets.ReadSocket.run(ReadSocket.java:83) </code></pre> <p>Could anyone please point me in the right direction of how to get this to work? Perhaps I should test the connection first somehow (if so, please say how?) Thanks</p> <p>Chris</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload