So I have a Java Client server application. When I am trying to send a single file to the server (using SSLSockets) it works fine (because the connection is closed straight after the byte array of the file is sent). Although, as soon as I try to send a second file inputStream reader loop hangs (probably receives more bytes after the transfer? IDK). I ll write the block of code slightly modified so the structures are visible underneath.
client
OutputStream = sslsocket.getOutputStream();
public void sendFile(Path pathOfFile){
byte[] bytesToSend = Files.readAllBytes(pathOfFile);
out.write(bytesToSend);
out.flush();
}
server
public void receiver(File file){
InputStream in = sslsocket.getInputStream();
byte[] fileBytes = new byte[sslsocket.getReceiveBufferSize()];
int temp = 0;
while ((temp = in.read(fileBytes)) > 0) { // stalls after a couple of reads
file.write(fileBytes , 0, temp);
}
}
so if I close the connection straight after the sendFile
method everything works fine. But if I even run the client on debug and breakpoint straight after the sendFile
method the server just freezes on the read()
method of the while
loop. What is going on??