Re: ServerSocket - OnClientRead event.


[ Related Articles and Replies ] [ DelphiLand FAQ ] [ Delphi Tutorials ]

Posted by WAllison on May 10, 2002 at 22:09:21:

In Reply to: ServerSocket - OnClientRead event. posted by Bill Adams on April 15, 2002 at 23:51:20:

: I've been reading up on some examples of how to receive data from the connection. Now, here's a snippet from one of the examples i'm looking at:

: var
: MsgLen : integer;
: Buf : string;
: LenReceived: integer;
: begin
: MsgLen := Socket.ReceiveLength;
: SetLength( Buf, MsgLen );
: LenReceived := Socket.ReceiveBuf( Buf[1],MsgLen );
: Buf := Copy( Buf, 1, LenReceived );

: Could someone explain what's going on here? I'm slightly confuse as to what's happening and i'm fairly new to Delphi so a simple explanation would be great.

//Determine the amount of info to read over the socket connection.
MsgLen := Socket.ReceiveLength;
//Allocate MsgLen bytes for Buf
SetLength( Buf, MsgLen );
//Transfer the data into buf+1 - returning the actual amount transfered;
LenReceived := Socket.ReceiveBuf( Buf[1], MsgLen);
//Make sure string is right length = copy itself to itself but use the actual Length Recieved - 
copies from index 1 to Length.
Buf := Copy( Buf, 1, LenReceived ); 
 

Related Articles and Replies:


[ Related Articles and Replies ] [ DelphiLand FAQ ] [ Delphi Tutorials ]