Test un port avec timeout

Forum sur la programmation en Visual 2008 C#

Test un port avec timeout

Postby andromeda » 24 Jun 2009 20:16

Code: Select all
int timeout = 2000; // Deux secondes
            TcpClient tcp = new TcpClient();
            IAsyncResult iar = tcp.BeginConnect(iphote, port, null, null);
            bool success = iar.AsyncWaitHandle.WaitOne(timeout, true);
            if (!success)
            {
                tcp.Close();
                // Traitement supplémentaire
            }
            // Succès
            tcp.EndConnect(iar);
            // Traitement supplémentaire
            tcp.Close();

Moderator - Forum
andromeda
 
Posts: 631
Joined: 29 Mar 2004 23:07

Return to Visual c#

Who is online

Users browsing this forum: No registered users and 1 guest

cron