I'm trying to send large files using socket programming in java for a p2p file sharing application. This code is sending 200-300 mb files without any problems, but for large files around 1 gb it is giving the error:-
    java.net.SocketException: Software caused connection abort: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at java.io.BufferedOutputStream.write(BufferedOutputStream.java:105)
    at FileSender.main(FileSender.java:28)
I'm already sending file in small chunks as suggested in many answers I got. What should I do to send 1 gb files. I'm programming on Windows.
Here are my codes:
Server
public class FileSender {
    public static void main(String...s)
    {
        BufferedOutputStream bos;
        String file="D:\\filename.mp4";
        try {
            ServerSocket sock=new ServerSocket(12345);      
            while(true)
            {   
                System.out.println("waiting");
                Socket soc=sock.accept();
                bos= new BufferedOutputStream(soc.getOutputStream());
                FileInputStream fis = new FileInputStream(file);
                BufferedInputStream bis = new BufferedInputStream(fis);
                int n=-1;
                byte[] buffer = new byte[8192];
                while((n = bis.read(buffer))>-1) 
                { 
                    bos.write(buffer,0,n);
                    System.out.println("bytes="+n);
                    bos.flush();
                }
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}
Reciever
public class FileReciev {
    public static void main(String...s)
    {
        try    
        {      
            Socket sock=new Socket("127.0.0.1",12345);
            File file=new File("D:\\newfilename.mp4");
            BufferedInputStream bis=new BufferedInputStream(sock.getInputStream());
            FileOutputStream fos = new FileOutputStream(file);
            int n;
            byte[] buffer = new byte[8192];
            System.out.println("Connected");
            while ((n = bis.read(buffer)) > -1) {
                System.out.println("bytes="+n);
                fos.write(buffer, 0, n);
                if(n<(8192)){
                    fos.close();
                    bis.close();
                    break;
                } 
                fos.flush();
            }
            System.out.println("recieved");
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}