Breyta

Deila með


TcpClient.BeginConnect Method

Definition

Begins an asynchronous request for a remote host connection.

Overloads

BeginConnect(IPAddress, Int32, AsyncCallback, Object)

Begins an asynchronous request for a remote host connection. The remote host is specified by an IPAddress and a port number (Int32).

BeginConnect(IPAddress[], Int32, AsyncCallback, Object)

Begins an asynchronous request for a remote host connection. The remote host is specified by an IPAddress array and a port number (Int32).

BeginConnect(String, Int32, AsyncCallback, Object)

Begins an asynchronous request for a remote host connection. The remote host is specified by a host name (String) and a port number (Int32).

BeginConnect(IPAddress, Int32, AsyncCallback, Object)

Source:
TCPClient.cs
Source:
TCPClient.cs
Source:
TCPClient.cs

Begins an asynchronous request for a remote host connection. The remote host is specified by an IPAddress and a port number (Int32).

public:
 IAsyncResult ^ BeginConnect(System::Net::IPAddress ^ address, int port, AsyncCallback ^ requestCallback, System::Object ^ state);
public IAsyncResult BeginConnect (System.Net.IPAddress address, int port, AsyncCallback? requestCallback, object? state);
public IAsyncResult BeginConnect (System.Net.IPAddress address, int port, AsyncCallback requestCallback, object state);
member this.BeginConnect : System.Net.IPAddress * int * AsyncCallback * obj -> IAsyncResult
Public Function BeginConnect (address As IPAddress, port As Integer, requestCallback As AsyncCallback, state As Object) As IAsyncResult

Parameters

address
IPAddress

The IPAddress of the remote host.

port
Int32

The port number of the remote host.

requestCallback
AsyncCallback

An AsyncCallback delegate that references the method to invoke when the operation is complete.

state
Object

A user-defined object that contains information about the connect operation. This object is passed to the requestCallback delegate when the operation is complete.

Returns

An IAsyncResult object that references the asynchronous connection.

Exceptions

The address parameter is null.

An error occurred when attempting to access the socket.

The Socket has been closed.

A caller higher in the call stack does not have permission for the requested operation.

The port number is not valid.

Remarks

The asynchronous BeginConnect operation must be completed by calling the EndConnect method. Typically, the method is invoked by the asyncCallback delegate.

This method does not block until the operation completes. To block until the operation completes, use one of the Connect method overloads.

For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously.

Note

If you receive NotSupportedException with message This protocol version is not supported while using IPv6 address, then make sure you enabled IPv6 in constructor by passing InterNetworkV6.

Applies to

BeginConnect(IPAddress[], Int32, AsyncCallback, Object)

Source:
TCPClient.cs
Source:
TCPClient.cs
Source:
TCPClient.cs

Begins an asynchronous request for a remote host connection. The remote host is specified by an IPAddress array and a port number (Int32).

public:
 IAsyncResult ^ BeginConnect(cli::array <System::Net::IPAddress ^> ^ addresses, int port, AsyncCallback ^ requestCallback, System::Object ^ state);
public IAsyncResult BeginConnect (System.Net.IPAddress[] addresses, int port, AsyncCallback? requestCallback, object? state);
public IAsyncResult BeginConnect (System.Net.IPAddress[] addresses, int port, AsyncCallback requestCallback, object state);
member this.BeginConnect : System.Net.IPAddress[] * int * AsyncCallback * obj -> IAsyncResult
Public Function BeginConnect (addresses As IPAddress(), port As Integer, requestCallback As AsyncCallback, state As Object) As IAsyncResult

Parameters

addresses
IPAddress[]

At least one IPAddress that designates the remote hosts.

port
Int32

The port number of the remote hosts.

requestCallback
AsyncCallback

An AsyncCallback delegate that references the method to invoke when the operation is complete.

state
Object

A user-defined object that contains information about the connect operation. This object is passed to the requestCallback delegate when the operation is complete.

Returns

An IAsyncResult object that references the asynchronous connection.

Exceptions

The addresses parameter is null.

An error occurred when attempting to access the socket.

The Socket has been closed.

A caller higher in the call stack does not have permission for the requested operation.

The port number is not valid.

Remarks

The asynchronous BeginConnect operation must be completed by calling the EndConnect method. Typically, the method is invoked by the asyncCallback delegate.

This method does not block until the operation completes. To block until the operation completes, use one of the Connect method overloads.

For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously.

This method is typically used immediately after a call to the BeginGetHostAddresses method, which can return multiple IP addresses for a single host.

Note

If you receive NotSupportedException with message This protocol version is not supported while using IPv6 address, then make sure you enabled IPv6 in constructor by passing InterNetworkV6.

Applies to

BeginConnect(String, Int32, AsyncCallback, Object)

Source:
TCPClient.cs
Source:
TCPClient.cs
Source:
TCPClient.cs

Begins an asynchronous request for a remote host connection. The remote host is specified by a host name (String) and a port number (Int32).

public:
 IAsyncResult ^ BeginConnect(System::String ^ host, int port, AsyncCallback ^ requestCallback, System::Object ^ state);
public IAsyncResult BeginConnect (string host, int port, AsyncCallback? requestCallback, object? state);
public IAsyncResult BeginConnect (string host, int port, AsyncCallback requestCallback, object state);
member this.BeginConnect : string * int * AsyncCallback * obj -> IAsyncResult
Public Function BeginConnect (host As String, port As Integer, requestCallback As AsyncCallback, state As Object) As IAsyncResult

Parameters

host
String

The name of the remote host.

port
Int32

The port number of the remote host.

requestCallback
AsyncCallback

An AsyncCallback delegate that references the method to invoke when the operation is complete.

state
Object

A user-defined object that contains information about the connect operation. This object is passed to the requestCallback delegate when the operation is complete.

Returns

An IAsyncResult object that references the asynchronous connection.

Exceptions

The host parameter is null.

An error occurred when attempting to access the socket.

The Socket has been closed.

A caller higher in the call stack does not have permission for the requested operation.

The port number is not valid.

Remarks

The asynchronous BeginConnect operation must be completed by calling the EndConnect method. Typically, the method is invoked by the asyncCallback delegate.

This method does not block until the operation completes. To block until the operation completes, use one of the Connect method overloads.

For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously.

Applies to