public boolean FileToByteArray(DatagramSocket socket, InetAddress dst_addr, int dst_port) throws Exception{
File file = new File("input.txt");
InputStream is = new FileInputStream(file);
long length = file.length();
byte[] bytes = new byte[(int) length];
int offset = 0, n = 0;
DatagramPacket out_pkt = null;
while (offset < bytes.length && (n = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += n;
out_pkt = new DatagramPacket(bytes, pkt_size, dst_addr, dst_port);
packetCount++;
System.out.println("*****************" + packetCount);
System.out.println(out_pkt.getLength());
socket.send(out_pkt);
}
is.close();
String s = new String(bytes);
System.out.println(s + " " + s.length()) ;
return true;
}
hi all, I am dealing with an assignment that needs me to send large text file through UDP. I am able to read the 10000 byte but when i set pkt_size to 1000, it only delivery 1000 byte which is 1KB of data over. How do i break large file to small packets to send?