RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TWinSocketStream.Read Method

Reads up to Count bytes from the socket connection into Buffer.

Pascal
function Read(var Buffer; Count: Longint): Longint; override;
C++
virtual __fastcall Longint Read( Buffer, Longint Count);

Use Read to read data from the socket connection when the number of bytes to be transferred is unknown. Buffer must have at least Count bytes allocated to hold the data that is read from the connection. Read returns the number of bytes actually transferred (which may be less than the number requested in Count.)  

Read may return 0 if the socket connection is extremely slow and the read operation has not completed after TimeOut milliseconds. This ensures that the Read method does not hang indefinitely when a problem occurs with the socket connection. 

To guard against the Read method timing out because of a slow connection, set Count fairly low, and make several calls to Read, rather than fewer calls with a large value of Count. 

To ensure that the socket connection is ready to send data before calling Read, use the WaitForData method. 

Unlike the ReadBuffer method, Read does not raise an exception if Count bytes are not read from the socket connection. 

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!