I am programming a tftp client and it works just fine, as long as i use default block size (512). But since it is a school assignment, i need to test it also with a block size of 1430 and 4300.
When i first comunicate with the server, i use this method:
public void setFilename( String s, String mode) {
byte []a = s.getBytes();
int i,j,k;
for ( i=0; i+2<lenght && i<a.length; i++ ) {
packet[i+2] = a[i];
}
packet[i+2] = 0;
a = mode.getBytes();
for ( j=0,i++; i<lenght && j<a.length; i++,j++ ) {
packet[i+2] = a[j];
}
packet[i+2] = 0;
}
It will set the filename i want to read. and it works just fine.
But i've changed it so i can define a block size:
public void setFilename( String s, String mode, String blockSize ) {
byte []a = s.getBytes();
int i,j,k;
for ( i=0; i+2<lenght && i<a.length; i++ ) {
packet[i+2] = a[i];
}
packet[i+2] = 0;
a = mode.getBytes();
for ( j=0,i++; i<lenght && j<a.length; i++,j++ ) {
packet[i+2] = a[j];
}
packet[i+2] = 0;
a = BLOCKSIZE.getBytes();
for ( k=0,i++; i<lenght && k<a.length; i++,k++ ) {
packet[i+2] = a[k];
}
packet[i+2] = 0;
a = blockSize.getBytes();
for ( k=0,i++; i<lenght && k<a.length; i++,k++ ) {
packet[i+2] = a[k];
}
packet[i+2] = 0;
}
and here BLOCKSIZE = "blksize" (string) and blockSize = 1430 (int); The problem is, it doesn't work :-/
Can somebody please explain to me how can i define the block size?
Thank you guys :-)