| Visual Basic (Declaration) | |
|---|---|
<CategoryAttribute("Connection")> <DescriptionAttribute("Raised when the value of the Connected property changes.")> Public Event ConnectedChangedEx As EventHandlerEx | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As Tcp Dim handler As EventHandlerEx AddHandler instance.ConnectedChangedEx, handler | |
| C# | |
|---|---|
[CategoryAttribute("Connection")] [DescriptionAttribute("Raised when the value of the Connected property changes.")] public event EventHandlerEx ConnectedChangedEx | |
| Managed Extensions for C++ | |
|---|---|
[CategoryAttribute("Connection")] [DescriptionAttribute("Raised when the value of the Connected property changes.")] public: __event EventHandlerEx* ConnectedChangedEx | |
| C++/CLI | |
|---|---|
[CategoryAttribute("Connection")] [DescriptionAttribute("Raised when the value of the Connected property changes.")] public: event EventHandlerEx^ ConnectedChangedEx | |
The following example demonstrates using the ConnectedChanged event to notify the user of the status of the connection.
| Visual Basic | Copy Code |
|---|---|
Private Sub Tcp1_ConnectedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tcp1.ConnectedChanged ' Get current state of connection If Tcp1.Connected Then Debug.WriteLine("Connection made") ' Display info about the local/remote endpoints Debug.WriteLine("Local endpoint: " + Tcp1.LocalEndPoint.ToString()) Debug.WriteLine("Remote endpoint: " + Tcp1.RemoteEndPoint.ToString()) Else Debug.WriteLine("Connection closed") End If End Sub | |
| C# | Copy Code |
|---|---|
private void tcp1_ConnectedChanged(object sender, System.EventArgs e) { // Get current state of connection if(tcp1.Connected) { Debug.WriteLine("Connection made"); // Display info about the local/remote endpoints Debug.WriteLine("Local endpoint: " + tcp1.LocalEndPoint.ToString()); Debug.WriteLine("Remote endpoint: " + tcp1.RemoteEndPoint.ToString()); } else Debug.WriteLine("Connection closed"); } | |
This event is raised when the value of the Object.Connected property changes. The value of the Object.Connected property changes whenever a TCP connection to a resource is either made or closed.
This event is useful in several scenarios, for example:
- Displaying the user when a connection has been terminated.
- Notifying the application if a connection has been terminated.
If you are using the PowerTCP component as a reference, you must create a method to handle the event yourself. For more information on using events using PowerTCP.NET within the Visual Studio.NET environment, see Using Events In PowerTCP.
Target Platforms: Microsoft .NET Framework 2.0