UDP的最大传输量是2048字节 所以数据要分包发送,每包最大为2K。 而接收可以一次用文件流接收。const bufsize = 2048;send端: var fstream:TFileStream; begin if totalsize > bufsize then begin sendsize := bufsize; totalsize := totalsize - sendsize; if totalsize = 0 then Exit; end //end of if totalsize > bufsize else //可以一次发送的 sendsize := totalsize; try fstream := TFilestream.creat; Fstream.read(buf,sendsize); ... finally fstream.free; end; ... ... end; //the end of the procedure
所以数据要分包发送,每包最大为2K。
而接收可以一次用文件流接收。const
bufsize = 2048;send端:
var
fstream:TFileStream;
begin
if totalsize > bufsize then
begin
sendsize := bufsize;
totalsize := totalsize - sendsize;
if totalsize = 0 then
Exit;
end //end of if totalsize > bufsize
else //可以一次发送的
sendsize := totalsize;
try
fstream := TFilestream.creat;
Fstream.read(buf,sendsize);
...
finally
fstream.free;
end;
...
...
end; //the end of the procedure