By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,677 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

Socket Blocked on Socket.Receive

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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]
Nov 20 '05 #2

P: n/a
if i need to break my blocked receive call to do a send (which is an
event for button click) and then go back again on a blocked receive,
how would i do that ?
thanks
Tom Shelton wrote:
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]


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.