CInternetServer::Read Method  
 
INT Read(
  SOCKET hSocket,  
  LPBYTE lpBuffer,  
  INT cbBuffer  
);
INT Read(
  LPBYTE lpBuffer,  
  INT cbBuffer  
);

Read data from the client.

Parameters

hSocket
An optional parameter that specifies the handle to the client socket. If this parameter is omitted, the socket handle for the active client session will be used. If this method is called outside of a server event handler, the socket handle must be specified.
lpBuffer
Pointer to the buffer in which the data will be stored. This parameter cannot be NULL.
cbBuffer
The maximum number of bytes to read and copy into the specified buffer. This value must be greater than zero.

Return Value

If the method succeeds, the return value is the number of bytes read. A return value of zero indicates that the client has closed the connection and there is no more data available to be read. If the method fails, the return value is INET_ERROR. To get extended error information, call the GetLastError method.

Remarks

The Read method will read up to the specified number of bytes and store the data in the buffer provided by the caller. If there is no data available to be read at the time this method is invoked, the session thread will block until at least one byte of data becomes available, the timeout period elapses or an error occurs. This method will return if any amount of data is sent by the client, and will not block until the entire buffer has been filled.

The application should never make an assumption about the amount of data that will be available to read. TCP considers all data to be an arbitrary stream of bytes and does not impose any structure on the data itself. For example, if the client is sending data to the server in fixed 512 byte blocks of data, it is possible that a single call to the Read method will return only a partial block of data, or it may return multiple blocks combined together. It is the responsibility of the application to buffer and process this data appropriately.

For applications that are built using the Unicode character set, it is important to note that the buffer is an array of bytes, not characters. If the client is sending string data to the server, it must be read as a stream of bytes and converted using the MultiByteToWideChar function. If the client is sending lines of text terminated with a linefeed or carriage return and linefeed pair, the ReadLine method will return a line of text at a time and perform this conversion for you.

To determine if there is data available to be read without causing the session thread to block, call the IsReadable method.

Requirements

Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header: Include cswsock10.h
Import Library: cswskv10.lib

See Also

IsReadable, IsWritable, Peek, ReadLine, Write, WriteLine