CSharp/C# >> TCP Socket class send() never blocks...

by ken.daniels » Sat, 05 Feb 2005 04:54:13 GMT

According to the documentation, the Socket.Send() is a blocking call,
however if I perform a Send() with the Server end point physically
unplugged,the Send call does not block, in fact it returns that the
message bytes were successfully sent.

I find this counter intuitive, since TCP should be gurarnteed delivery,
why does the Send() call seem to succeed, even when the end point was
disconnected.

Any Thoughts???

Thanks,
KD


Similar Threads

1. Sockets class question - sending TCP data - CSharp/C#

2. socket.send sends wait for another socket.send

hi , I have a problem with socket.send

mesajlar = Encoding.ASCII.GetBytes("UGIR");

socketResultValue = socket.Send(mesajlar,0,mesajlar.Length, 
SocketFlags.None);

socketResultValue = 
socket.Receive(mesajlar,0,mesajlar.Length,SocketFlags.None);

mesajlar = Encoding.ASCII.GetBytes("UIST,1");

socketResultValue = 
socket.Send(mesajlar,0,mesajlar.Length,SocketFlags.None);

socketResultValue = 
socket.Receive(mesajlar,0,mesajlar.Length,SocketFlags.None);


this is the code  i am using ,  It sends all together , so it makes error.
How can I handle this   i mean

send UGIR and wait

send UIST,1 and wait  and so on

?



thanks in advance



3. looking for code sample for non-blocking TCP sockets - CSharp/C#

4. read from TCP/IP socket with blocking

So, I currently have code for reading in TCP/IP messages that looks
something like this:

StreamReader reader = new StreamReader(new NetworkStream(mySocket)));
while (true)
{
   string inputString = reader.ReadLine();
   _newMessages.Enqueue(inputString);
}

This is one thread in my application, and as it is a non-blocking
infinite loop, it is causing my application to consume 100% of my
CPU.

Is there a simple method of rewriting this to cause it to block when
there's nothing else to read? (thereby freeing up CPU)

I attempted to use StreamReader.ReadBlock(), but then realized that
this really doesn't block when the stream is empty either.

Thanks!

5. TCP, Sockets, Blocking etc

6. TCP 10055 error for blocking socket

7. Timeout probelm for blocking socket TCP connections

8. Understanding socket.Send() with TCP and confirmation

Hi All,

I am trying to understand the blocking method socket.Send().
The call blocks as expected, but does this mean, it returnes after the
underlying TCP layer got a confirmation, that the send data was received by
the socket on the remote end? Can I count on that? Do I understand TCP
correctly in that, it gives confirmation [on the underlying level]? I do not
expect, that a .Net based receiver got that data when socket.Send()
terminates!

Hope I was clear,
thanks and best regards,
Manfred Braun

(Private)
Lange Roetterstrasse 7
D68167 Mannheim
Germany

mailto: XXXX@XXXXX.COM 
(Remove the anti-spam-underscore to mail me!)