I got working server and client applications, they work perfect while sending small files, but when I try to send for example movie file that is 700mb over socket it gives m
The problem is that you are trying to load the entire file at once into memory (via readFully
), which exceeds your heap space (which by default is 256mb I think).
You have two options:
For option one you can try something like:
DataInputStream in = new DataInputStream(new FileInputStream("file.txt"));
byte[] arr = new byte[1024];
try {
int len = 0;
while((len = in.read(arr)) != -1)
{
// send the first len bytes of arr over socket.
}
} catch(IOException ex) {
ex.printStackTrace();
}