Async Timeout events for TCP connections.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Mark Smith (shofu_au_at_yahoo.com.au)
Date: 06/16/04


Date: 16 Jun 2004 01:28:40 -0700

Hi ,

Is it possible in .Net to define a async timer callback. What I am
wanting to do is declare a time-out condition that gets executed
should the something timeout.

The reason I want to do this is to handle host being down that I am
trying to connect to using TCPIP. Then after a timeout automatically
try another host and just continue trying hosts until someone accepts
a connection, varying my timeout as I loop.

Function1 (string hostname)
{
Socket sock = new Socket(AddressFamily.InterNetwork,
                         SocketType.Stream,
                         ProtocolType.Tcp);
IPEndPoint iep = new IPEndPoint(IPAddress.Parse(hostname, 9999);
IAsyncResult ar = sock.BeginConnect(iep, new
AsyncCallback(ConnectedMethod), sock);

Call another ASYNC routine (TryAnotherHost) that defines timer event
callback which if not cancelled executes within 15 seconds.
}

void ConnectedMethod(IAsyncResult iar)
{
     Socket socket = (Socket)iar.AsyncState;
     socket.EndConnect(iar);

     cancel the timer???
   <do all my normal stuff>
}

void TryAnotherHost (IAsyncResult iar)
{
     Socket socket = (Socket)iar.AsyncState;
     socket.EndConnect(iar);

     socket.Close();
     function1 ("another");
}

Is this possible and what routines should I review to achieve this.

Thanks

Mark



Relevant Pages

  • Re: simple thread
    ... that procedure B only executes after procedure A has returned? ... when the Host calls them ... > in the proper order procedure B can test for this flag ... But I can't call Proc B until Proc A has returned an ...
    (alt.comp.lang.borland-delphi)
  • Re: [PHP] $_SESSION variable gets lost on FORM action
    ... However, before that, my PHP scripts check if the session for this user ... If it detects a timeout, ... happens when the user is filling a form, the action that it executes ... I'm thinking that this is the problem because I've eliminated all the occurrences where the SESSION var was cleared until only one exists and it was after a Location Header. ...
    (php.general)
  • Re: External activator timeout
    ... It has WAITFOR timeout to 3 seconds. ... it executes every second with timeout 3 seconds. ... Links for SQL Server Books Online: ...
    (microsoft.public.sqlserver.programming)
  • Re: how to determine the best timeout value
    ... Are you sure you are not being blocked when you timeout? ... > an xml document that is passed to the stored procedure in a string. ... > If I run the code that executes the stored procedure it executes fine ...
    (microsoft.public.sqlserver.connect)
  • External activator timeout
    ... exec sp_executesql N'WAITFOR (RECEIVE ... It has WAITFOR timeout to 3 seconds. ... it executes every second with timeout 3 seconds. ...
    (microsoft.public.sqlserver.programming)