See Also

Tcp Class  | Tcp Members  | Overload List

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Language

Visual Basic

C#

C++

C++/CLI

Show All

server
Remote hostname or address in dot notation.
serverPort
Remote port, a number between 1 and 65535, inclusive.
client
Optional local hostname or address in dot notation. Use "" as default.
clientPort
Optional local port, a number between 1 and 65535, inclusive. Use 0 as default.
state
User state information.
See Also Languages PowerTCP SSL Sockets for .NET

BeginConnect(String,Int32,String,Int32,Object) Method

Dart.PowerTCP.SslSockets Namespace > Tcp Class > BeginConnect Method : BeginConnect(String,Int32,String,Int32,Object) Method

Connect to a server asynchronously, specifying the local interface to use. The EndConnect event is raised when completed.

[Visual Basic]
<DescriptionAttribute("Connect to a server asynchronously. The EndConnect event is raised when completed.")> Overloads Public Function BeginConnect( _    ByVal server As String, _    ByVal serverPort As Integer, _    ByVal client As String, _    ByVal clientPort As Integer, _    ByVal state As Object _ ) As IAsyncResult
[C#]
[DescriptionAttribute("Connect to a server asynchronously. The EndConnect event is raised when completed.")] public IAsyncResult BeginConnect(    string server,    int serverPort,    string client,    int clientPort,    object state );
[C++]
[DescriptionAttribute("Connect to a server asynchronously. The EndConnect event is raised when completed.")] public: IAsyncResult* BeginConnect(    string* server,    int serverPort,    string* client,    int clientPort,    Object* state )
[C++/CLI]
[DescriptionAttribute("Connect to a server asynchronously. The EndConnect event is raised when completed.")] public: IAsyncResult^ BeginConnect(    String^ server,    int serverPort,    String^ client,    int clientPort,    Object^ state )

Parameters

server
Remote hostname or address in dot notation.
serverPort
Remote port, a number between 1 and 65535, inclusive.
client
Optional local hostname or address in dot notation. Use "" as default.
clientPort
Optional local port, a number between 1 and 65535, inclusive. Use 0 as default.
state
User state information.

Return Type

An IAsyncResult that represents the asynchronous operation, which could still be pending.

Exceptions

ExceptionDescription
InvalidOperationExceptionBeginXXX method used without providing an EndXXX event handler.

Remarks

Use this method if you wish to connect to a host transparently with minimal application impact, as execution occurs on another thread. This method begins to asynchronously connect to the server. Upon completion (on both success and failure) the EndConnect event is raised. An EventArgs object is passed into this event, containing information about the event. If the connection succeeds, the ConnectedChanged event is raised. Once the connection has been made, you can send and receive data from the remote device.

If you are using the Tcp component as a reference, you must "wire up" the event yourself. This involves creating a method as the event handler that implements the EventHandler delegate.

For more information on implementing and handling events using PowerTCP.NET, see the topic, Using Events In PowerTCP.

To connect synchronously, use the Connect method.

Example

The following example demonstrates asynchronously connecting using the BeginConnect method.

[Visual Basic] 

Private Sub Test()
   ' Begin to asynchronously connect to an echo port.
   Tcp1.BeginConnect("atropos", 7)
End Sub

Private Sub Tcp1_EndConnect(ByVal sender As Object, ByVal e As ExceptionEventArgs) Handles Tcp1.EndConnect
   ' Connect complete, check for any exceptions
   If e.Exception Is Nothing Then
      ' Now send some data.
      Tcp1.Send("hello")

      ' Receive the data back.
      Dim seg As Segment = Tcp1.Receive()
      Debug.WriteLine(seg.ToString())
   End If
End Sub

[C#] 


private void Test()
{
  
// Begin to asynchronously connect to an echo port.
  
tcp1.BeginConnect("atropos", 7);
}

private void tcp1_EndConnect(object sender, ExceptionEventArgs e)
{
  
// Connect complete, check for any exceptions
  
if(e.Exception == null)
  {
     
// Now send some data.
     
tcp1.Send("hello");

     
// Receive the data back.
     
Segment seg = tcp1.Receive();

     Debug.WriteLine(seg.ToString());
  }
}
                

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Tcp Class  | Tcp Members  | Overload List


Send comments on this topic.

Documentation version 1.1.2.0.

© 2008 Dart Communications.  All rights reserved.