Exemplo n.º 1
0
        public static bool IsListenerAtAddress(IPv4AddressPort address)
        {
            TcpClient    client = new TcpClient();
            ListenerTest test   = new ListenerTest(client);

            try
            {
                client.BeginConnect(address.AddressAsIPv4Address.AddressAsIPAddress, address.Port, new AsyncCallback(ListenerTesterConnectCallback), test);
                if (test.WaitEvent.Wait(30 * 1000) == false)
                {
                    client.Close();
                }
            }
            catch (Exception) {}
            return(test.IsConnected);
        }
Exemplo n.º 2
0
        static void ListenerTesterConnectCallback(IAsyncResult ar)
        {
            ListenerTest test = ar.AsyncState as ListenerTest;

            try
            {
                test.Client.EndConnect(ar);

                test.IsConnected = test.Client.Connected;

                test.Client.Close();
            }
            catch (Exception) {}
            finally
            {
                test.WaitEvent.Set();
            }
        }