Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.net.SocketException after successful connection with webservice
    primarykey
    data
    text
    <p>I connected android application to the webservice. The code goes like that: printing to console flag1, retrieving information, printing to console flag 2. When program stops, flag1 is printed and less than half of information is retrieved. In logcat the error is "DEBUG/SntpClient(78): request time failed: java.net.SocketException: Address family not supported by protocol" and the second flag is not printed. What's wrong with it, here's the code:</p> <pre><code> System.out.println("flag1"); BufferedInputStream bis = new BufferedInputStream(is); while (bis.available() &gt; 0) { System.out.print((char)bis.read()); } System.out.println("flag2"); </code></pre> <p>Added: logcat output:</p> <pre><code>10-06 20:55:15.585: INFO/System.out(460): flag1 10-06 20:55:33.136: DEBUG/SntpClient(78): request time failed: java.net.SocketException: Address family not supported by protocol 10-06 21:00:33.146: DEBUG/SntpClient(78): request time failed: java.net.SocketException: Address family not supported by protocol 10-06 21:03:22.656: DEBUG/AndroidRuntime(473): &gt;&gt;&gt;&gt;&gt;&gt; AndroidRuntime START com.android.internal.os.RuntimeInit &lt;&lt;&lt;&lt;&lt;&lt; 10-06 21:03:22.656: DEBUG/AndroidRuntime(473): CheckJNI is ON 10-06 21:03:23.206: DEBUG/AndroidRuntime(473): Calling main entry com.android.commands.pm.Pm 10-06 21:03:23.326: DEBUG/dalvikvm(275): GC_EXPLICIT freed 10K, 5% free 6302K/6595K, paused 5ms+3ms </code></pre> <p>Connection is created as:</p> <pre><code>URL url = new URI(address).toURL(); InputStream is = url.openStream(); </code></pre> <p>Edit: When I want to read from inputstream not byte by byte but with buffer:</p> <pre><code>byte[] buffer = new byte[1024]; int n = 0; System.out.println("flag1"); while ((n = is.read(buffer)) != -1) System.out.write(buffer, 0, n); System.out.println("flag2"); </code></pre> <p>It prints flag1, half of the inputstream and then neither throws exception nor prints flag2:</p> <pre><code>10-06 21:26:09.016: INFO/System.out(804): flag1 10-06 21:26:09.356: INFO/System.out(804): less than half of the inputstream 10-06 21:26:17.846: DEBUG/dalvikvm(195): GC_EXPLICIT freed 163K, 5% free 6829K/7175K, paused 9ms+3ms </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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