Note that there are some explanatory texts on larger screens.

plurals
  1. POJava File Transfer getting stuck halfway
    text
    copied!<p>I am trying to send a file (an image sent as a byte array) with the client and then the server should receive said byte array to make further use of it. However when I click on the "send" to send the image the file transfer starts (as I get a sentImage.jpg in my Desktop) but it gets stuck for some reason I can't figure out and the image never gets correctly sent.</p> <p>Here's the part that receives from the server (it already accepted the connection):</p> <pre><code> public void run(){ try { byte[] receivedData = new byte[1024]; BufferedInputStream bis = new BufferedInputStream(client.getInputStream()); // while(bis.read() != -1){ s.acquireUninterruptibly(); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("C:\\Users\\Admin\\Desktop\\sentImage.jpg")); while ((incoming = bis.read(receivedData)) != -1) { bos.write(receivedData, 0, incoming); } s.release(); n.release(); bis.close(); bos.flush(); // } } catch (IOException e) { e.printStackTrace(); } } </code></pre> <p>and the client is sending here:</p> <pre><code>public void sendImageResult() { new Thread(new Runnable() { public void run() { try { int inside = 0; Socket socket = new Socket("localhost", 4444); File myImageFile = new File("C:\\Users\\Admin\\Desktop\\test.jpg"); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(myImageFile)); BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream( )); byte[] byteArray = new byte[1024]; while ((inside = bis.read(byteArray)) != -1){ bos.write(byteArray,0,inside); } bis.close(); bos.flush(); } catch (UnknownHostException ex) { System.out.println("No se pudo establecer la conexión."); ex.printStackTrace(); } catch (FileNotFoundException fnf){ fnf.printStackTrace(); } catch(IOException ioe){ ioe.printStackTrace(); } } }).start(); } </code></pre>
 

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