S
sky2008
Unregistered / Unconfirmed
GUEST, unregistred user!
const
PackSize = 200;
接收数据过程
=================================================
procedure TForm1.RecvData( skt: TSocket );
var
getbuf, putbuf, buf: array[ 0..PackSize ] of char;
TempStream: TMemoryStream;
n, t, i: integer;
begin
Log( '开始接收数据...' );
i := 1;
t := 0;
try
TempStream := TMemoryStream.Create;
repeat
n := recv( skt, buf, PackSize, 0 );
TempStream.WriteBuffer( buf, n );
//Memo1.Lines[ Memo1.Lines.Count - 1 ] := '已接收数据... ' + intToStr( i * PackSize );
inc( t, n );
Log( '已接收数据... ' + intToStr( t ) );
inc( i );
Application.ProcessMessages;
Sleep( 100 );
until n = 0;
TempStream.Position := 0;
memo2.Lines.LoadFromStream( TempStream );
finally
TempStream.Free;
Log( '接收完成!' );
end;
end;
发送数据过程
===================================
procedure TForm1.SendData( skt: TSocket );
var
{getbuf, putbuf, } buf: array[ 0..PackSize ] of char;
TempStream: TMemoryStream;
n, t, i: integer;
begin
Log( '开始发送数据...' );
i := 1;
t := 0;
try
TempStream := TMemoryStream.Create;
Memo2.Lines.SaveToStream( TempStream );
TempStream.Position := 0;
repeat
n := TempStream.Read( buf, PackSize );
send( skt, buf, sizeof( buf ), 0 );
//Memo1.Lines[ Memo1.Lines.Count - 1 ] := '已发送数据... ' + intToStr( i * PackSize );
inc( i );
inc( t, n );
Log( '已发送数据... ' + intToStr( t ) );
Application.ProcessMessages;
sleep( 100 );
until n <> PackSize;
finally
TempStream.Free;
Log( '发送完成!' );
end;
end;
PackSize = 200;
接收数据过程
=================================================
procedure TForm1.RecvData( skt: TSocket );
var
getbuf, putbuf, buf: array[ 0..PackSize ] of char;
TempStream: TMemoryStream;
n, t, i: integer;
begin
Log( '开始接收数据...' );
i := 1;
t := 0;
try
TempStream := TMemoryStream.Create;
repeat
n := recv( skt, buf, PackSize, 0 );
TempStream.WriteBuffer( buf, n );
//Memo1.Lines[ Memo1.Lines.Count - 1 ] := '已接收数据... ' + intToStr( i * PackSize );
inc( t, n );
Log( '已接收数据... ' + intToStr( t ) );
inc( i );
Application.ProcessMessages;
Sleep( 100 );
until n = 0;
TempStream.Position := 0;
memo2.Lines.LoadFromStream( TempStream );
finally
TempStream.Free;
Log( '接收完成!' );
end;
end;
发送数据过程
===================================
procedure TForm1.SendData( skt: TSocket );
var
{getbuf, putbuf, } buf: array[ 0..PackSize ] of char;
TempStream: TMemoryStream;
n, t, i: integer;
begin
Log( '开始发送数据...' );
i := 1;
t := 0;
try
TempStream := TMemoryStream.Create;
Memo2.Lines.SaveToStream( TempStream );
TempStream.Position := 0;
repeat
n := TempStream.Read( buf, PackSize );
send( skt, buf, sizeof( buf ), 0 );
//Memo1.Lines[ Memo1.Lines.Count - 1 ] := '已发送数据... ' + intToStr( i * PackSize );
inc( i );
inc( t, n );
Log( '已发送数据... ' + intToStr( t ) );
Application.ProcessMessages;
sleep( 100 );
until n <> PackSize;
finally
TempStream.Free;
Log( '发送完成!' );
end;
end;