请教FSocket.SendBuf or Send 问题? (100分)

  • 主题发起人 主题发起人 jxhdy2001
  • 开始时间 开始时间
J

jxhdy2001

Unregistered / Unconfirmed
GUEST, unregistred user!
请问地发送大数据时,怎么样才能得到发送的的大小?
WinSock中Send函数在发送一小包一小包时会产生哪些消息?
 
send 函数如果调用有效会返回发送的大小,
发送大数据最好分割一下!!
 
To Leaber:
在Midas中数据的读取和提交所使用的是ReceiveBuf和SendBuf,而我现在要做的就是在读取数据和提交数据时,得到数据读取和提交的进度!读取数据我已经实现了,但提交时,跟了很久都没的找到所以然?所以就这里问了?
 
你现在就是如何显示进度的问题?
 
在TSocketTransport类中扩展一个事件,然后在Receive函数处理!
 
采用交叉握手!就是,首先告诉对方多大,然后每发送一个就+1
 
to dcsdcds:
呵呵!数据传输的代码不是我写的,是Borland原码啊!

{*******************************************************}
{ }
{ Borland Delphi Visual Component Library }
{ Streamed Connection classes }
{ }
{ Copyright (c) 1997,99 Inprise Corporation }
{ }
{*******************************************************}

unit SConnect;
{$R-}
interface
uses
Windows, Messages, Classes, SysUtils, MConnect, ScktComp, WinSock, objbrkr, WinINet;
type
//>------------------11.11----------------------------------------------------
TDataReserved= procedure (Sender: TObject; BytesReceive, BytesCount: Integer) of object;
//<---------------------------------------------------------------------------
TSocketTransport = class(TInterfacedObject, ITransport)
private
FEvent: THandle;
FInterceptor: IDataIntercept;
FCreateAttempted: Boolean;
//>------------------说 明---------------------------------------
FOnDataReserved: TDataReserved;
//<-------------------------------------------------------------------------
property OnDataReserved: TDataReserved read FOnDataReserved write FOnDataReserved;

function TSocketTransport.Receive(WaitForInput: Boolean; Context: Integer;TimeOut:Integer=15): IDataBlock;
var
RetLen, Sig, StreamLen: Integer;
P: Pointer;
FDSet: TFDSet;
TimeVal: PTimeVal;
RetVal, ByteReceive, ByteCount: Integer;
begin



ByteCount:= StreamLen;
ByteReceive:=0;
while StreamLen > 0 do
begin
RetLen := FSocket.ReceiveBuf(P^, StreamLen);
if RetLen = 0 then
raise ESocketConnectionError.CreateRes(@SSocketReadError);
if RetLen > 0 then
begin
Inc(ByteReceive,RetLen);
[green] if Assigned(FOnDataReserved) then
FOnDataReserved(self, ByteReceive, ByteCount);[/green]
Dec(StreamLen, RetLen);
Inc(Integer(P), RetLen);
end;
end;
[green]但这下面的就没法加代码处理了![/green]
function TSocketTransport.Send(const Data: IDataBlock): Integer;
var
P: Pointer;
begin
Result := 0;
InterceptOutgoing(Data);
P := Data.Memory;
FSocket.SendBuf(P^, Data.Size + Data.BytesReserved);
end;

 
var
P: Pointer;
LenP,SendLen,Count: integer;
begin
Result := 0;
P := Data.Memory;
Count := (Data.Size + Data.BytesReserved);
SendLen := 0;
FProgress := 0;
Lenp := 8000;
TimeVal.tv_sec := 2;
TimeVal.tv_usec := 0;
while SendLen < Count do
begin
if (Count - SendLen) < Lenp then
LenP := Count - SendLen;
FSocket.SendBuf(Pointer(Integer(P) + SendLen)^, Lenp);
SendLen := SendLen + Lenp;
end;
 
谢谢帮助
 
后退
顶部