PowerTCP Mail for .NET
Close(LingerOption) Method
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > Tcp Class > Close Method : Close(LingerOption) Method




linger
If null is used, a graceful disconnect will occur without blocking execution of your application.
Close the connection.

Syntax

Visual Basic (Declaration) 
<DescriptionAttribute("Close the connection.")>
Public Overloads Sub Close( _
   ByVal linger As LingerOption _
) 
Visual Basic (Usage)Copy Code
Dim instance As Tcp
Dim linger As LingerOption
 
instance.Close(linger)
C# 
[DescriptionAttribute("Close the connection.")]
public void Close( 
   LingerOption linger
)
Managed Extensions for C++ 
[DescriptionAttribute("Close the connection.")]
public: void Close( 
   LingerOption* linger
) 
C++/CLI 
[DescriptionAttribute("Close the connection.")]
public:
void Close( 
   LingerOption^ linger
) 

Parameters

linger
If null is used, a graceful disconnect will occur without blocking execution of your application.

Example

The following example demonstrates connecting to an echo port, sending data, receiving data, then closing the connection.
Visual BasicCopy Code
Private Sub TcpDemo()

   ' Connect to echo port.
   Tcp1.Connect("atropos", "7")

   ' Send some data
   Dim seg As Segment = Tcp1.Send("Hello")

   ' Display info
   Debug.WriteLine("Bytes of data sent: " & seg.Count)
   Debug.WriteLine("Data sent: " & seg.ToString())

   ' Receive response (this should be the same as the sent data)
   seg = Tcp1.Receive()

   ' Display info
   Debug.WriteLine("Bytes of data received: " & seg.Count)
   Debug.WriteLine("Data received: " & seg.ToString())

   ' Since connection is to an echo port, the client has to
   ' close the connection.
   Try
      Tcp1.Close()
   Catch ex As Exception
      ' Error, just dispose the object.
      Tcp1.Dispose()
   End Try

   '* Output
   '* --------------------------
   '* Bytes of data sent: 5
   '* Data sent: Hello
   '* Bytes of data received: 5
   '* Data received: Hello
   '*
End Sub
C#Copy Code
private void TcpDemo()
{
   // Connect to echo port.
   tcp1.Connect("atropos", "7"); 

   // Send some data
   Segment seg = tcp1.Send("Hello");

   // Display info
   Debug.WriteLine("Bytes of data sent: " + seg.Count);
   Debug.WriteLine("Data sent: " + seg.ToString());

   // Receive response (this should be the same as the sent data)
   seg = tcp1.Receive();

   // Display info
   Debug.WriteLine("Bytes of data received: " + seg.Count);
   Debug.WriteLine("Data received: " + seg.ToString());

   // Since connection is to an echo port, the client has to
   // close the connection.
   try
   {
      tcp1.Close();
   }
   catch(Exception ex)
   {
      // Error, just dispose the object.
      tcp1.Dispose();
   }

   /* Output
    * --------------------------
    * Bytes of data sent: 5
    * Data sent: Hello
    * Bytes of data received: 5
    * Data received: Hello
    */
}

Remarks

This method is the recommended way to explicitly close a connection. The Tcp.Connected property is set to false when the connection is closed.

The LingerOption parameter controls the amount of time to remain connected after the socket is closed.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

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