System.Net.Sockets.TcpClient.ConnectAsync C# (CSharp) Méthode

ConnectAsync() public méthode

public ConnectAsync ( IPAddress address, int port ) : System.Threading.Tasks.Task
address IPAddress
port int
Résultat System.Threading.Tasks.Task
        public Task ConnectAsync(IPAddress address, int port) => ConnectAsyncCore(address, port);

Same methods

TcpClient::ConnectAsync ( string host, int port ) : System.Threading.Tasks.Task

Usage Example

        public void Download()
        {
            using (TcpClient tcpClient = new TcpClient())
            {
                if (!tcpClient.ConnectAsync(IpAdress, 80).Wait(TIMEOUT))
                {
                    Console.WriteLine("La connection vers " + Uri + " a timeout");
                    return;
                }
                stream = tcpClient.GetStream();

                var byteRequest = Encoding.ASCII.GetBytes(string.Format(GetRequest, Uri.LocalPath, Uri.Host));
                stream.Write(byteRequest, 0, byteRequest.Length);
                bufferSize = tcpClient.ReceiveBufferSize;

                List<byte> srcByte = new List<byte>();
                while (!stream.DataAvailable) ;
                while (stream.DataAvailable)
                {
                    byte[] data = new byte[bufferSize];
                    int read = stream.Read(data, 0, bufferSize);
                    srcByte.AddRange(data.Take(read));
                }

                ParseRequest(srcByte.ToArray());
            }
        }
All Usage Examples Of System.Net.Sockets.TcpClient::ConnectAsync