-(Void) udp_sendfile :( nsstring *) filename;
{
Nsstring * filepath = [nstemporarydirectory () stringbyappendingstring: Filename];
Nsdata * sdata = [[nsdata alloc] initwithcontentsoffile: filepath];
Byte * Sarr;
Int sumpak, curpak;
// Subpacket Transmission
Int Total = sdata. length, curloc, srctotal = sdata. length;
Sumpak = srctotal/8000;
If (srctotal % 8000 = 0)
{
}
Else
{
Sumpak = sumpak + 1;
}
Curpak = 0;
Curloc = 0;
Nslog (@ "Total: % d", total );
// File Information header: Ea filetype paknum1 paknum2 paknum2 paknum3 paksum1 paksum2 paksum3 paksum4 datalen1 datalen2 CHK1 CHK2 temp
While (total> 8000)
{
Curpak ++;
Nsdata * pdata = [sdata subdatawithrange: nsmakerange (curloc, 8000)];
Sarr = new byte [8016];
Byte * bytes;
Sarr [0] = 0xea; // header flag
Sarr [1] = 0xea; // header flag
Sarr [2] = 0; // file type
Sarr [3] = curpak/256/256/256; // Package number
Sarr [4] = curpak % (256*256*256)/256;
Sarr [5] = curpak % (256*256)/256;
Sarr [6] = curpak % (256*256) % 256;
Sarr [7] = sumpak/256/256/256; // Total number of packages
Sarr [8] = sumpak % (256*256*256)/256;
Sarr [9] = sumpak % (256*256)/256;
Sarr [10] = sumpak % (256*256) % 256;
Sarr [11] = 8000/256;
Sarr [12] = 8000% 256;
Int check = 0;
Bytes = (byte *) [pdata bytes];
For (INT I = 0; I <8000; I ++)
{
Check = check + bytes [I];
Sarr [I + 16] = bytes [I];
}
Sarr [13] = check/256;
Sarr [14] = check % 256;
Sarr [15] = 0;
Nsdata * sdata = [[nsdata alloc] initwithbytes: Sarr length: 8016];
[Udpclient senddata: sdata tohost: serverip port: 8009 withtimeout: 5000 Tag: 1];
Total = total-8000;
Curloc = fig + 8000;
Sarr = nil;
Nslog (@ "% d", 8000 );
}
If (total> 0)
{
Curpak ++;
Nsdata * pdata = [sdata subdatawithrange: nsmakerange (curloc, total)];
Sarr = new byte [Total + 16];
Byte * bytes = (byte *) [pdata bytes];
Sarr [0] = 0xea; // header flag
Sarr [1] = 0xea; // header flag
Sarr [2] = 0; // file type
Sarr [3] = curpak/256/256/256; // Package number
Sarr [4] = curpak % (256*256*256)/256;
Sarr [5] = curpak % (256*256)/256;
Sarr [6] = curpak % (256*256) % 256;
Sarr [7] = sumpak/256/256/256; // Total number of packages
Sarr [8] = sumpak % (256*256*256)/256;
Sarr [9] = sumpak % (256*256)/256;
Sarr [10] = sumpak % (256*256) % 256;
Sarr [11] = 8000/256;
Sarr [12] = 8000% 256;
Int check = 0;
For (INT I = 0; I <total; I ++)
{
Check = check + bytes [I];
Sarr [I + 16] = bytes [I];
}
Sarr [13] = check/256;
Sarr [14] = check % 256;
Sarr [15] = 0;
Nsdata * sdata = [[nsdata alloc] initwithbytes: Sarr length: Total + 16];
[Udpclient senddata: sdata tohost: serverip port: 8009 withtimeout: 5000 Tag: 1];
Nslog (@ "% d", total );
}
}