This function works the same as the send () function. The main difference between send () and recv () is that the buffer pointer passed to the recv () function must point to an empty buffer, and the buffer length parameter indicates how much memory was allocated for the buffer.
Public Function ReceiveData(strData, lngBytesReceived) As Boolean
Const MAX_BUFF_SIZE = 10000
Dim Buff(0 To MAX_BUFF_SIZE) As Byte
Dim WSAResult As Long
WSAResult = recv(mlngSocket, Buff(0), MAX_BUFF_SIZE, 0)
If WSAResult = SOCKET_ERROR Then
SetLastErrorCode "Error in RecvData::recv"
strData = ""
lngBytesReceived = 0
ReceiveData = False
lngBytesReceived = WSAResult
Buff(lngBytesReceived) = 0
strData = Left(StrConv(Buff(), vbUnicode), lngBytesReceived)
ReceiveData = True
Like the send () function, recv () returns the number of bytes received. If an error occurs, the function returns SOCKET_ERROR. The recv () function is also a blocking function, so it will not return until the remote host sends something or the connection is lost. You can use the IsDataAvailable () method to determine if there is some data to retrieve or not.
DOWNLOAD List >>
Visual Basic Source Code. TCP Client-Server