System.Net.Sockets.Socket.Blocking = True doesn't work

  • Thread starter Thread starter Robert A. van Ginkel
  • Start date Start date
R

Robert A. van Ginkel

In I ask the question how I
can see if all the data is on the other side of the connection.
I got as answer that I should use the blocking property.
I tried this I don't see any diffents, I am sending 10Mb and the
Send/BeginSend command doesn't wait till the data is on the remotepoint.
Can somebody pls. explain this.

Regards Robert.
 
Robert A. van Ginkel said:
In I ask the question how I
can see if all the data is on the other side of the connection.
I got as answer that I should use the blocking property.
I tried this I don't see any diffents, I am sending 10Mb and the
Send/BeginSend command doesn't wait till the data is on the remotepoint.
Can somebody pls. explain this.
Robert -

Whether you are using synchronous or asynchronous sockets, there
is no possible way for one end of the connection to know that it has
received all of the data unless it is told by the other end of the
connection. With TCP, there is no guarantee that all of the data will
arrive in a steady stream. There are often delays between packets as
they are sent on the network. This causes the Receive() method to
assume the data stream is complete and finish the call. It is the
receiving program's job to determine if there is really more data to
be read. There are two common techniques to do this:

If only one data stream is sent between the two sides, then the
sending side can close the socket when it is finished sending bytes.
The receiving side can then read data until the Recieve() method
returns 0 bytes, indicating that the connection was closed, and all of
the data was received.

If you must leave the connection active after the data stream, the
best way to determine if all of the data is received is by having the
sending side first send the size of the data to the receiving side,
then send the actual data. The receiving side can then loop on the
Receive() methods (either sync or async) until it knows all of the
data has been received (by keeping track of the number of bytes
received).

Hope this helps shed some light on your problem.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471433012.html
 
Dear Mr. Blum,

Thank you for responding.

First of all you explain that Localpoint never knows if Remotepoint has
received all the data, only if Remotepoint confirms this in sending a TCP/IP
package back.
I disagree, thats more UDP/IP, in TCP/IP socket there is an engine that
makes sure u receive/send the packages or else there is a socket error.
While TCP/IP is a async protocol, in a socket there is a mechanism that
keeps track of sequence and what was/wasn't send, bottomline: if a packet is
lost it is being send again.
Sample case:
if u send 1 byte from a client in Canada to a server in Australia with a 28k
modem thats being shared by an office of 30 people connected to the slowest
profider. (etc.)
What I want to say is that 1 byte may take 1 minute, and I use 1 byte as an
example because I don't want to make a discussion

There are three stadiums(simplified):
A My object sends to the Winsock, (buffer is being fed, no data on the
network, no data on the remote point)
B Winsock processes his buffer and sends on the network (buffer is empty,
data on the network, no data on the remote point)
C All data is correctly processed and transported (buffer is empty, no data
on the network,data on the remote point)

I achieve (A) ofcourse, I would really want to know (C), but I would be
satisfied with (B).
I know (B) can be achieved, I hope (C) is too.

P.S. I know of lingering and all other socket options, but at this point I
am not intrested in that, I just want to know why Socket.Blocking doesn't
work. If I send 10Mb over the socket with or without blocking mode, it
transmits my data to the socket buffer, and thats all, thats (A). I couldn't
find it in the FrameWork so I read the winsock API but couldn't find a
function I could use.

Regards,
Robert
 
Dear Rich Blum,

I shouldn't control the remotepoint, I work following a specified RFC.

BeginRead,EndRead with his callback sends 0 bytes to close, but I am talking
about sending.
I found the code of .NET framework for unix. And BeginSend uses just a
different thread that invokes the send command.
The networkstream/tcpclient/tcplistener is just a wrapper of the socket. I
am making my own wrapper because, those wrappers are buggy and doesn't give
me propper info.

My question is about blocking, BeginSend with blocking doesn't work (see
documentation of blocking property)
And Send returns imitially, it writes to an internal buffer, And I need to
know when that buffer is empty.
Why? Because If u read my other message 'Socket still
sending?'(U see I want to start my timeout function after the remotepoint got the
data/after the data is processed in the local winsock buffer.

Regards, Robert
 
Back
Top