I am implementing a GET request where the client sends a request to the server. The server responds with the correct file-resource, after the client writes on the socket, the server receives it and sends back the header and the file, but the client blocks when using socket.inputStream.
Client:
byte[] requestInBytes=clientRequest.getClientRequest().getBytes();
out.write(requestInBytes);
out.flush();
System.out.println("SENT REQUEST");
in=socket.getInputStream();
byte[]serverResponse=in.readAllBytes();
System.out.println("RECEIVED RESPONSE");
Server:
fileInputStream = Extensions.getFileInputStream(targetURI);
String contentType = Extensions.getContentType(targetURI);
Long contentLength = fileInputStream.getChannel().size();
responseBuilder.append("Date: " + Extensions.getCurrentDate() + "\r\n");
responseBuilder.append("Server: macOS\r\n");
responseBuilder.append("Last-Modified: " + Extensions.getLastModifiedDate(targetURI) + "\r\n");
responseBuilder.append("Content-Length: " + contentLength.toString() + "\r\n");
responseBuilder.append("Content-Type: " + contentType + "\r\n");
responseBuilder.append("Connection: Closed\r\n");
outputStream.write(responseBuilder.toString().getBytes());
outputStream.write(("\r\n").getBytes());
outputStream.write(fileInputStream.readAllBytes());
outputStream.flush();
outputStream.close();
System.out.println("FILE SENT TO CLIENT");