PowerTCP Mail for .NET
Connected Property
See Also  Send comments on this topic.
Dart.PowerTCP.Mail Namespace > Tcp Class : Connected Property




Gets the connected state of the connection.

Syntax

Visual Basic (Declaration) 
<BrowsableAttribute(False)>
<DescriptionAttribute("Returns true when an active connection exists.")>
Public ReadOnly Property Connected As Boolean
Visual Basic (Usage)Copy Code
Dim instance As Tcp
Dim value As Boolean
 
value = instance.Connected
C# 
[BrowsableAttribute(false)]
[DescriptionAttribute("Returns true when an active connection exists.")]
public bool Connected {get;}
Managed Extensions for C++ 
[BrowsableAttribute(false)]
[DescriptionAttribute("Returns true when an active connection exists.")]
public: __property bool get_Connected();
C++/CLI 
[BrowsableAttribute(false)]
[DescriptionAttribute("Returns true when an active connection exists.")]
public:
property bool Connected {
   bool get();
}

Property Value

true if the TCP connection is connected to a remote resource and authenticated; otherwise, false.

Example

The following example demonstrates the code required to build a simple echo server.
Visual BasicCopy Code
Private Sub StartServer()
   ' Begin listening for connections on port 7.
   Server1.Listen(7)
End Sub

Private Sub Server1_Connection(ByVal sender As Object, ByVal e As ConnectionEventArgs) Handles Server1.Connection
   ' This event is raised on a new thread when a connection is received.
   Try
      ' Keep receiving data until connection is closed
      Do While (e.Tcp.Connected)
         ' Receive data.
         Dim seg As Segment = e.Tcp.Receive()

         ' Echo data back to client
         e.Tcp.Send(seg.ToString())
      Loop
   Catch ex As Exception
      'eat exception  
   End Try
End Sub
C#Copy Code
private void StartServer()
{
   // Begin listening for connections on port 7.
   server1.Listen(7);
}

private void server1_Connection(object sender, ConnectionEventArgs e)
{
   // This event is raised on a new thread when a connection is received.
   try
   {
      // Keep receiving data until connection is closed
      while(e.Tcp.Connected)
      {
         // Receive data.
         Segment seg = e.Tcp.Receive();

         // Echo data back to client.
         e.Tcp.Send(seg.ToString());
      }
   }
   catch(Exception ex)
   {
      // eat any exceptions
   }
}

Remarks

If the PowerTCP component is connected to a remote resource AND authenticated, this property returns true. If this property is false, the connection was either never connected, is no longer connected, or is connected but not yet authenticated. When receiving data from the server, this property is a good way to tell if all data has been received. Keep receiving data in a loop until this property equals false.

When using PowerTCP components which make use of the Tcp component as the underlying connection, this property returns the same value as the Object.Connection.Connected property (where Object.Connection exposes the Tcp object used for the connection).

The Object.ConnectedChanged and Object.ConnectedChangedEx events are raised whenever this property changes.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

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