System.Net.Sockets.TcpClient and System.Net.Sockets.TcpListener. Handling errors

C

Claire

Hi
Im writing an application using the above controls in blocking mode. Ive not
used them before and I'm more used to asynchronous socket programming
utilizing socket events.
As there are no events associated to the controls, I'm wondering how i
monitor connection state.

On my server side, i loop through a thread that tests the DataAvailable
flag.
On client side, i opened the connection then closed it again after some time
by calling Close() on the socket.
I expected an exception on the server side when calling DataAvailable, but
it just kept looping happily.

I know there are graceful and nongraceful disconnections between sockets,
it's difficult to trap the non graceful ones but in this case I had closed
the client side gracefully.

The server side application is designed for multiple socket connections and
i'd like some pointers to understanding disconnections better.

thank you
 
G

Guest

Claire said:
Hi
Im writing an application using the above controls in blocking mode. Ive not
used them before and I'm more used to asynchronous socket programming
utilizing socket events.
As there are no events associated to the controls, I'm wondering how i
monitor connection state.

On my server side, i loop through a thread that tests the DataAvailable
flag.
On client side, i opened the connection then closed it again after some time
by calling Close() on the socket.
I expected an exception on the server side when calling DataAvailable, but
it just kept looping happily.

I know there are graceful and nongraceful disconnections between sockets,
it's difficult to trap the non graceful ones but in this case I had closed
the client side gracefully.

The server side application is designed for multiple socket connections and
i'd like some pointers to understanding disconnections better.

thank you

Hi Claire,

I also checked the DataAvailable is always successful even after the socket
has been
closed by remote server.
As per MSDN it should throw an exception of type IOException or
SocketException:
_ If the remote host shuts down or closes the connection, DataAvailable
throws a SocketException_

I have experienced similar problems when i was coding for Socket, have a
look at the following thread named [.NET Socket]:

http://msdn.microsoft.com/newsgroup...-DC48AB0DA5C9&dglist=&ptlist=&exp=&sloc=en-us
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top