| Visual Basic (Declaration) | |
|---|---|
<DescriptionAttribute("Connect to a server asynchronously. The EndConnect event is raised when completed.")> Public Overloads Function BeginConnect( _ ByVal server As String, _ ByVal serverPort As Integer _ ) As IAsyncResult | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As Tcp Dim server As String Dim serverPort As Integer Dim value As IAsyncResult value = instance.BeginConnect(server, serverPort) | |
| C# | |
|---|---|
[DescriptionAttribute("Connect to a server asynchronously. The EndConnect event is raised when completed.")] public IAsyncResult BeginConnect( string server, int serverPort ) | |
| Managed Extensions for C++ | |
|---|---|
[DescriptionAttribute("Connect to a server asynchronously. The EndConnect event is raised when completed.")] public: IAsyncResult* BeginConnect( string* server, int serverPort ) | |
| C++/CLI | |
|---|---|
[DescriptionAttribute("Connect to a server asynchronously. The EndConnect event is raised when completed.")] public: IAsyncResult^ BeginConnect( String^ server, int serverPort ) | |
Parameters
- server
- Remote hostname or address in dot notation.
- serverPort
- Remote port, a number between 1 and 65535, inclusive.
Return Value
An IAsyncResult that represents the asynchronous operation, which could still be pending.| Exception | Description |
|---|---|
| System.InvalidOperationException | BeginXXX method used without providing an EndXXX event handler. |
| Visual Basic | Copy Code |
|---|---|
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# | Copy Code |
|---|---|
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()); } } | |
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 Tcp.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 Tcp.Connect method.
Target Platforms: Microsoft .NET Framework 2.0