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

by eWFyb24 » Mon, 26 Sep 2005 17:57:01 GMT

Hi,

I need a code sample for doing this:

- support for multiple agents that know each other and can talk each other
over a non-blocking TCP socket.
each agent can send and recieve data to/from each other.
- handling agent down events (i don't know how to do it in an elegant way
when using the socket select method).

I prefer to use the Socket.Select method.
All the socket operations must be in a non-blocking mode.

Thanks.


Similar Threads

1. TCP Socket class send() never blocks...

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

2. read from TCP/IP socket with blocking - CSharp/C#

3. TCP, Sockets, Blocking etc

I'm pretty new to VB .net and Network coding, what I'm trying to do is 
interact with a NNTP server to retrieve a list of news groups.

When I run thru' debug I basically get what I'm after, when I run without 
debug the results vary - which to me suggests it's some form of sync problem 
with my 'writes and reads'.

I've set up a connection to a server and have sent a 'List' command to get a 
'group list', I've set up my connection buffer at 32k, I'm assuming I'm 
blocking on the stream read, the question is how to I control receiving a 
complete returned message - which could be 500k. I've tried various do-loop 
controls, some based on MSDN examples such as 'Loop While 
NStream.DataAvailable' and the attached which I'd hoped would loop until a 
message which was less then the complete buffer was returned - but it all 
seems hit and miss.

thanks

        Dim numberOfBytesRead As Integer = 0
        Dim sb As New StringBuilder

        Do
            numberOfBytesRead = NStream.Read(bytes, 0, CInt 
Connection.ReceiveBufferSize))
            If numberOfBytesRead = 0 Then
                Exit Do
            End If
           sb.Append(Encoding.ASCII.GetString(bytes, 0, numberOfBytesRead))
            totallength = sb.Length
        Loop Until numberOfBytesRead < Connection.ReceiveBufferSize

4. TCP 10055 error for blocking socket

5. Timeout probelm for blocking socket TCP connections

Hello!
I have a TCP Client connection in a blocking mode, ie connect(...) stops 
for a certain amount of time trying to establish a connection to a 
remote host.

Problem: This timeout is too big for my purposes. I would like to 
decrease it to an configurable time.
(I know I could set the socket in non-blocking mode and wait for the 
completion of the connection but I would like to use blocking mode)

So...
1. Is it possible to set the connect(...) timeout for a specific socket?
2. How can I do this (examples please)? :-)

Greatful for any help, comments of hints!

Sincerely
tlwc

6. Remoting socket error 10035 non-blocking socket exception - .Net Framework

7. looking for a CF C# socket client sample

I'm looking for a simple CF C#  tcp/ip client that
I can  use as a start point (I'm new to C# and .NET).

I found a couple async socket samples, but none
of them worked with the CF. One used Send()
(which is not allowed in CF with non-blocking
sockets ). Other used classes not present in CF.

Any help will be appreciated.

Omar





8. BUG in non-blocking socket connect ? - CSharp/C#