System.Net.Sockets.TcpClient.BeginConnect C# (CSharp) Method

BeginConnect() public method

public BeginConnect ( IPAddress address, int port, AsyncCallback requestCallback, object state ) : IAsyncResult
address IPAddress
port int
requestCallback AsyncCallback
state object
return IAsyncResult
        public IAsyncResult BeginConnect(IPAddress address, int port, AsyncCallback requestCallback, object state)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Enter(this, address);

            IAsyncResult result = BeginConnectCore(address, port, requestCallback, state);

            if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
            return result;
        }

Same methods

TcpClient::BeginConnect ( string host, int port, AsyncCallback requestCallback, object state ) : IAsyncResult

Usage Example

Ejemplo n.º 1
0
        public static IPAddress[] GetAllHostsWithOpenPort(IPAddress start, IPAddress end)
        {
            ConsoleColor c = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Yellow;

            uint from = IPAddressToUInt(start);
            uint to = IPAddressToUInt(end);
            uint between = to - from;

            string title = Console.Title;
            List<IPAddress> list = new List<IPAddress>();

            for (uint i = from; i <= to; i++)
            {
                Console.Title = ((double)i / between * 100) + "% | " + i;
                string[] temp = new IPAddress(i).ToString().Split('.');
                string[] newTemp = { temp[3], temp[2], temp[1], temp[0] };
                IPAddress ip = IPAddress.Parse(string.Join(".", newTemp));
                try
                {
                    TcpClient client = new TcpClient();
                    client.BeginConnect(ip, Port, new AsyncCallback(CallBack), client);
                }
                catch (SocketException) // no such host | port closed | port busy
                {
                    //Console.WriteLine("{0}:{1} is not ready for your commands", ip.ToString(), Port);
                }
            }
            Console.Title = title;
            System.Threading.Thread.Sleep(5000);
            Console.ForegroundColor = c;
            return list.ToArray();
        }
All Usage Examples Of System.Net.Sockets.TcpClient::BeginConnect