How: Affecting TcpClient Connect( ) timeout ?

  • Thread starter Thread starter Lee Gillie
  • Start date Start date
L

Lee Gillie

I have seen some suggest you use the ReadTimeout and WriteTimeout
properties to control this, but I have tried this, and it does not work.
I have a difficult to reproduce scenario where connection attempts are
hanging for 5 minutes before eventually failing. I need a much shorter
timeout on my client.

I think the delay is that the server has partially started negotiating
the connection - the OS has answered the call, but the bind has not
passed off the incoming connection request to the server process yet.
The server runs on VMS.
 
Lee said:
I have seen some suggest you use the ReadTimeout and WriteTimeout
properties to control this, but I have tried this, and it does not work.
I have a difficult to reproduce scenario where connection attempts are
hanging for 5 minutes before eventually failing. I need a much shorter
timeout on my client.

I think the delay is that the server has partially started negotiating
the connection - the OS has answered the call, but the bind has not
passed off the incoming connection request to the server process yet.
The server runs on VMS.

Ok, I think I figure this out.

One wants to make a Socket and manually connect it asynchronously using
BeginConnect. A manual reset event can then time the attempt to connect,
and stall the caller until either the asynchronous connect activity
occurs, or else the timed manual reset event wait expires. Once a
manually connected socket has been made, the next issue is how to get
the TcpClient to use it. There is a Client property on TcpClient, but
one must derive a from TcpClient to use it. I simply wrapped up all the
timeout enabled connect methods in this wrapper class. I provided
overlaods to the base class Connect routines which add a timeout
parameter. I chose to exclude the DNS work from the timeout.

- Lee
 

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

Back
Top