PowerTCP Telnet for .NET CF
State Property
See Also  Send comments on this topic.
Dart.Common Namespace > TcpBase Class : State Property




Gets the status of the connection.

Syntax

Visual Basic (Declaration) 
Public ReadOnly Property State As ConnectionState
Visual Basic (Usage)Copy Code
Dim instance As TcpBase
Dim value As ConnectionState
 
value = instance.State
C# 
public ConnectionState State {get;}
Managed Extensions for C++ 
public: __property ConnectionState get_State();
C++/CLI 
public:
property ConnectionState State {
   ConnectionState get();
}

Example

This example demonstrates using the component State to update the UI.
C#Copy Code
private void myComponent_StateChanged(object sender, EventArgs e)
{
    //Always raised when connection is established or closed (State property changes)
    switch (myComponent.State)
    {
        case Dart.Common.ConnectionState.Connected:
        case Dart.Common.ConnectionState.ConnectedAndSecure:
            //Update interface to indicate connection
            textDisplay.ReadOnly = false;
            textDisplay.BackColor = Color.WhiteSmoke;
            Text = (myComponent.State == Dart.Common.ConnectionState.Connected)
                ? APP_NAME + "  [Connected to " + myComponent.RemoteEndPoint.Address.ToString() + ":" +
                    myComponent.RemoteEndPoint.Port.ToString() + "]"
                : APP_NAME + "  [Securely Connected to " + myComponent.RemoteEndPoint.Address.ToString() + ":" +
                    myComponent.RemoteEndPoint.Port.ToString() + "]";
            break;

        case Dart.Common.ConnectionState.Closed:
            //Update interface to indicate no connection
            textDisplay.ReadOnly = true;
            textDisplay.BackColor = Color.Silver;
            this.Text = APP_NAME + "  [Not Connected]";
            break;
    }
}
C#Copy Code
Private Sub myComponent_StateChanged(ByVal sender As Object, ByVal e As EventArgs) Handles myComponent.StateChanged
	'Always raised when Connection is established or closed (State property changes)
	Select Case myComponent.State
		Case Dart.Common.ConnectionState.Connected, Dart.Common.ConnectionState.ConnectedAndSecure
			'Update interface to indicate connection
			textDisplay.ReadOnly = False
			textDisplay.BackColor = Color.WhiteSmoke
			If (myComponent.State = Dart.Common.ConnectionState.Connected) Then
				Text = APP_NAME & "  [Connected to " & myComponent.RemoteEndPoint.Address.ToString() _
					& ":" & myComponent.RemoteEndPoint.Port.ToString() & "]"
			Else
				Text = APP_NAME & "  [Securely Connected to " & myComponent.RemoteEndPoint.Address.ToString() _
					& ":" & myComponent.RemoteEndPoint.Port.ToString() & "]"
			End If

		Case Dart.Common.ConnectionState.Closed
			'Update interface to indicate no connection
			textDisplay.ReadOnly = True
			textDisplay.BackColor = Color.Silver
			Me.Text = APP_NAME & "  [Not Connected]"
	End Select
End Sub

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 4.2
© 2010 Dart Communications. All Rights Reserved.