A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.connectasync below:

Socket.ConnectAsync Method (System.Net.Sockets) | Microsoft Learn

Source:
Socket.cs
Source:
Socket.cs
Source:
Socket.cs
Source:
Socket.cs

Begins an asynchronous request for a connection to a remote host.

public:
 static bool ConnectAsync(System::Net::Sockets::SocketType socketType, System::Net::Sockets::ProtocolType protocolType, System::Net::Sockets::SocketAsyncEventArgs ^ e);
public static bool ConnectAsync(System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType, System.Net.Sockets.SocketAsyncEventArgs e);
static member ConnectAsync : System.Net.Sockets.SocketType * System.Net.Sockets.ProtocolType * System.Net.Sockets.SocketAsyncEventArgs -> bool
Public Shared Function ConnectAsync (socketType As SocketType, protocolType As ProtocolType, e As SocketAsyncEventArgs) As Boolean
Parameters Returns

true if the I/O operation is pending. The Completed event on the e parameter will be raised upon completion of the operation.

false if the I/O operation completed synchronously. In this case, The Completed event on the e parameter will not be raised and the e object passed as a parameter may be examined immediately after the method call returns to retrieve the result of the operation.

Exceptions

An argument is not valid. This exception occurs if multiple buffers are specified, the BufferList property is not null.

The Socket is listening or a socket operation was already in progress using the SocketAsyncEventArgs object specified in the e parameter.

An error occurred when attempting to access the socket.

The local endpoint and the RemoteEndPoint are not the same address family.

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

Remarks

If you are using a connection-oriented protocol, the M:System.Net.Sockets.Socket.ConnectAsync(System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,System.Net.Sockets.SocketAsyncEventArgs) method starts an asynchronous request for a connection to the remote host. If you are using a connectionless protocol, ConnectAsync establishes a default remote host specified by the socketType and protocolType parameters.

To be notified of completion, you must create a callback method that implements the EventHandler<SocketAsyncEventArgs> delegate and attach the callback to the SocketAsyncEventArgs.Completed event.

The caller must set the SocketAsyncEventArgs.RemoteEndPoint property to the IPEndPoint of the remote host to connect to.

The caller may set the SocketAsyncEventArgs.UserToken property to any user state object desired before calling the ConnectAsync method, so that the information will be retrievable in the callback method. If the callback needs more information than a single object, a small class can be created to hold the other required state information as members.

If you are using a connectionless protocol such as UDP, you do not have to call ConnectAsync before sending and receiving data. You can use SendToAsync and ReceiveFromAsync to communicate with a remote host. If you do call ConnectAsync, any datagrams that arrive from an address other than the specified default will be discarded. If you want to change the default remote host, call the ConnectAsync method again with the desired endpoint.

If you wish to set the default remote host to a broadcast address, you must first call SetSocketOption and set Broadcast to true. If this is not done, the ConnectAsync method will throw a SocketException.

The following properties and events on the System.Net.Sockets.SocketAsyncEventArgs object are required:

Optionally, a buffer may be provided that will atomically be sent on the socket after the ConnectAsync method succeeds. In this case, the SocketAsyncEventArgs.Buffer property needs to be set to the buffer containing the data to send and the SocketAsyncEventArgs.Count property needs to be set to the number of bytes of data to send from the buffer. Once a connection is established, this buffer of data is sent.

If you are using a connection-oriented protocol and do not call Bind before calling ConnectAsync, the underlying service provider will assign the most appropriate local network address and port number.

If you are using a connectionless protocol, the service provider will not assign a local network IP address and port number until you call the SendAsync or ReceiveAsync methods.

The ConnectAsync method throws NotSupportedException if the address family of the Socket and the SocketAsyncEventArgs.RemoteEndPoint are not the same address family.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4