In article <7a**************************@posting.google.com >, Qindong Zhang wrote:
My socket application blocked at socket.receiver() after received all
information from sender. Should socket.Receive() return 0 after no
more data available? Note: My socket object was not close on both
client/server side. My cached for further use.
While bytesReceived > 0
byteBuffer = New Byte(1024) {}
bytesReceived = handler.Receive(byteBuffer)
If bytesReceived > 0 Then
ReDim Preserve m_data(bytesTotalReceived + bytesReceived - 1)
Array.Copy(byteBuffer, 0, m_data, bytesTotalReceived,
bytesReceived)
bytesTotalReceived = bytesTotalReceived + bytesReceived
End If
End While
Socket.Receive is a blocking call. If there is no data in the pipe, it
will wait. It returns 0 if the remote endpoint shuts down.
Basically, you need to have a transmision protocol defined between the
client and server so that you know how much data to read. Commonly, if
the data is varying lengths the stream will be delimited with a control
sequence - such as CR+LF - but that is not a requirement of TCP, that is
an application layer function. Then when you read from the socket, you can
check for the presence of this sequence to determine if you have reached
the end of the current transmission.
--
Tom Shelton
MVP [Visual Basic]