questo è il codice,
// Sender
try {
File localFile = new File("shared/"+fileName);
OutputStream out = socket.getOutputStream();
InputStream fis = new FileInputStream(localFile);
int length;
byte[] buffer = new byte[4096];
while((length = fis.read(buffer)) != -1)
out.write(buffer, 0, length);
fis.close();
out.close();
}
catch(Exception e){}
// Receiver
try {
File downloadFile = new File("incoming/"+fileName);
IntputStream ois = connectedSocket.getIntputStream();
OutputStream fos = new FileOutputStream(downloadFile);
int length;
byte[] buffer = new byte[4096];
while((length = ois.read(buffer)) != -1){
fos.write(buffer, 0, length);
fos.close();
ois.close();
}
catch(Exception e){}
Il problema è che il sender manda quasi tutto il file ad eccezione dell'ultimo pezzo che non riesce a riempire completamente il buffer... quindi il receiver non prende mai il -1 nella sua read e non esce mai dal ciclo.
Da quanto ho capito il sender si blocca nell ultima read...
cosa sbaglio? : (
anche mettendo il buffer ad 1, il sender non prende mai -1, tantomeno il receiver : (
grazie dell aiuto