BlockWrite将文件读入MemoryStream,然后SendStream分块发送。udp传输是尽最大努力投递,所以你最好是自己制订一个通信规则,用来判断发送接收状态。

解决方案 »

  1.   

    cowboy1999(牛仔) ,你能说的更详细些吗?
      

  2.   

    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