Connect to a server asynchronously, specifying the local interface to use. The Tcp.EndConnect event is raised when completed.
Syntax
| Visual Basic (Usage) | Copy Code |
|---|
Dim instance As Tcp
Dim server As String
Dim serverPort As Integer
Dim client As String
Dim clientPort As Integer
Dim state As Object
Dim value As IAsyncResult
value = instance.BeginConnect(server, serverPort, client, clientPort, 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 Value
An IAsyncResult that represents the asynchronous operation, which could still be pending.
Exceptions
Example
The following example demonstrates asynchronously connecting using the BeginConnect method.
| 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());
}
} |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 2.0
See Also