Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Socket download multiple files fired?
    primarykey
    data
    text
    <p>I want to download multiple images from server. I open socket and download first image and when I want download second image in this socket, download not proceed, socket are closed. My code below...</p> <p>public class ClientThread implements Runnable {</p> <pre><code> public void run() { try { Log.d("ClientActivity", "C: Connecting..."); SocketAddress sockaddr = new InetSocketAddress(serverIpAddress, SERVERPORT); socket = new Socket(); socket.setKeepAlive(true); socket.connect(sockaddr, 5000); if (socket.isConnected()) { final DataInputStream input = new DataInputStream(socket.getInputStream()); final PrintWriter output = new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); output.println("GET /way/images/profile/1231 HTTP/1.1"); output.println("Host: 192.168.1.2"); output.println("User-Agent: Java"); output.println("Accept: */*"); output.println("Connection: Keep-Alive"); output.println(""); output.flush(); String line; File file = new File("/sdcard/aaa.png"); if (!file.exists()) { file.createNewFile(); } FileOutputStream fileOut = new FileOutputStream(file); System.out.println("Getting first file"); while ( (line = input.readLine()) != null ) { System.out.println(line); fileOut.write(line.getBytes()); } System.out.println("First file finished"); fileOut.flush(); fileOut.close(); output.println("GET /way/images/profile/1231 HTTP/1.1"); output.println("Host: 192.168.1.2"); output.println("User-Agent: Java"); output.println("Accept: */*"); output.println("Connection: Keep-Alive"); output.println(""); output.flush(); file = new File("/sdcard/aaa1.png"); if (!file.exists()) { file.createNewFile(); } fileOut = new FileOutputStream(file); System.out.println("Getting second file"); while ( (line = input.readLine()) != null ) { System.out.println(line); fileOut.write(line.getBytes()); } System.out.println("Second file finished"); fileOut.flush(); fileOut.close(); input.close(); output.close(); socket.close(); } Log.d("ClientActivity", "C: Closed."); } catch (Exception e) { Log.e("ClientActivity", "C: Error", e); connected = false; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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