I use bellow codes for send file file master to client but when I use mulltiple time this code for different file program give "SOCKET CLOSED" error because of I close socket using " out.close(); " and "in.close();" I can't solve these problem Do you have any suggestion. Also I try to don't close socket but it is not worked next files is not send this time
private void SendFiletoClient(Socket Socket, String fileName) {
try {
File file = new File(MasterPath + "/" + fileName);// Get the size of the file
long length = file.length();
byte[] bytes = new byte[16 * 1024];
InputStream in = new FileInputStream(file);
OutputStream out = Socket.getOutputStream();
int count;
while ((count = in.read(bytes)) > 0) {
out.write(bytes, 0, count);
}
out.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/////
private void addFileToClient(Socket Socket, String fileName) {
File file = new File(MasterPath + fileName);
try {
file.createNewFile();
InputStream in = Socket.getInputStream();
OutputStream out = new FileOutputStream(MasterPath + fileName);
byte[] bytes = new byte[16 * 1024];
int count;
while ((count = in.read(bytes)) > 0) {
out.write(bytes, 0, count);
}
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}