const BLOCKSIZE = 1024 * 4;<br>const TRT_FILE = '001';<br>const TRT_NOP = '999';<br>//=============================<br><br>客户端<br>procedure TF_Main.ClientSocket1Read(Sender: TObject;<br> Socket: TCustomWinSocket);<br>var<br> li_actbyte: integer; //当前分块(此块)流的大小<br> lb_tmpbuff: array[0..BLOCKSIZE] of char; //流缓存空间<br>begin<br> li_actbyte := Socket.ReceiveLength;<br> Socket.ReceiveBuf(lb_tmpbuff, li_actbyte); //追加接收流<br> ist_picstream.Write(lb_tmpbuff, li_actbyte); //写入内存<br> StatusBar1.Panels[1].Text := '传输中...';<br> StatusBar1.Panels[2].Text := inttostr(ist_picstream.Size div 1024) + 'Kb已传输';<br> if li_actbyte < BLOCKSIZE then //“流” 剩最后一块时或未开始接文件时 执行<br> begin<br> ist_picstream.Position := 0; //内存指向首位置<br> if is_transtype = TRT_FILE then //传的是文件 执行<br> begin<br> Save_localFIleName:= Save_FilePath + extractfilename(Save_FilePathName);<br> ist_picstream.SaveToFile(Save_localFIleName);<br> StatusBar1.Panels[3].Text := extractfilename(Save_FilePathName) + '保存成功';<br> StatusBar1.Panels[1].Text := '传输完毕';<br> // clientsocket1.Close; //================================<br> end;<br> ist_picstream.Clear;<br> socket.SendText(TRT_NOP);<br> if Breadover = true then F_play.Show<br> else TwtoWav(Save_localFIleName,Save_FilePath,true) ;<br> //=======================================================<br> if listbox1.Count > 0 then listbox1.Items.Delete(0);<br> listbox1.Refresh;<br> Breadover:=false;<br> if listbox1.Count > 0 then TimerSend(sender);<br><br> end<br> else socket.SendText(is_cmdtext); //继续该文件//文件名<br>end;<br><br>服务端:<br><br>procedure TForm1.ServerSocket1ClientRead(Sender: TObject;<br> Socket: TCustomWinSocket);<br>var<br> ls_receive: string;<br> ls_info: string;<br> ls_cmd: string;<br> i: integer;<br>begin<br> ls_receive := Socket.ReceiveText;<br> ls_cmd := copy(ls_receive, 1, 3);<br> ls_info := copy(ls_receive, 4, length(ls_receive) - 3);<br> if ls_cmd = TRT_FILE then<br> begin<br> if FileExists(ls_info) then uf_sendfile(ls_info)<br> else begin<br> for I := 0 to (serversocket1.socket.ActiveConnections - 1) do<br> begin<br> serversocket1.Socket.Connections.SendText('004ERROR');<br> end;<br> end;<br> end;<br>end;<br><br>procedure TForm1.uf_sendfile(as_filename: string);<br>var<br> li_actbyte: longint;<br> lb_tmpbuff: array[0..BLOCKSIZE - 1] of char;<br> I, j: integer;<br>begin<br> if ist_memstrem.Size = 0 then<br> begin<br> ist_memstrem.LoadFromFile(as_filename);<br> il_leave := ist_memstrem.Size;<br> for j := 0 to (serversocket1.socket.ActiveConnections - 1) do<br> begin<br> serversocket1.Socket.Connections[j].SendText('003' + IntTOstr(il_leave));<br> end;<br> end;<br> if il_leave > BLOCKSIZE then<br> li_actbyte := BLOCKSIZE<br> else li_actbyte := il_leave;<br> il_leave := il_leave - li_actbyte;<br> ist_memstrem.ReadBuffer(lb_tmpbuff, li_actbyte);<br> if il_leave = 0 then<br> ist_memstrem.Clear;<br> for I := 0 to (serversocket1.socket.ActiveConnections - 1) do<br> begin<br> serversocket1.Socket.Connections.SendBuf(lb_tmpbuff, li_actbyte);<br> end;<br>end;<br>我在本机上可以传完,可是在网络上只传第一个包,不传以后的,也就是都小于4K<br>文件在500k到10M 之间