Closes the stream.

Namespace:  Quanser.Communications
Assembly:  Quanser.Communications (in Quanser.Communications.dll)

Syntax

Visual Basic (Declaration)
Public Sub Close
C#
public void Close()
Visual C++
public:
void Close()
JavaScript
function close();

Remarks

This method closes the stream. All resources associated with the stream are freed. If an error occurs, then it throws a StreamException. If the connection is already closed it is considered an error condition.

Examples

This example connects to a remote host serving on TCP/IP port 18000 using blocking I/O and default send and receive buffer sizes. It closes the stream when communications are finished.
C# Copy Code
Stream  stream = new Stream();
String  uri    = "tcpip://localhost:18000";
bool    done   = false;

try {
    stream.Connect(uri);

    try {
        /* ... communicate with client using blocking I/O ... */
    } catch (Exception ex) {
        Console.WriteLine("Error communicating with client on URI '" + uri + "'. " + ex);
    }

    stream.Close();
} catch (Exception ex) {
    Console.WriteLine("Unable to connect to URI '" + uri + "'. " + ex);
}
Visual Basic Copy Code
Dim stream As New Stream()
Dim uri As String = "tcpip://localhost:18000"
Dim done As Boolean = False

Try
    stream.Connect(uri)

    Try
        ' ... communicate with client using blocking I/O ...
    Catch ex As Exception
        Console.WriteLine("Error communicating with client on URI '" & uri & "'. " & ex.ToString())
    End Try

    stream.Close()
Catch ex As Exception
    Console.WriteLine("Unable to connect to URI '" & uri & "'. " & ex.ToString())
End Try
Visual C++ Copy Code
Stream^  stream = new Stream();
String^  uri    = L"tcpip://localhost:18000";
bool     done   = false;

try {
    stream->Connect(uri);

    try {
        /* ... communicate with client using blocking I/O ... */
    } catch (Exception ex) {
        Console::WriteLine("Error communicating with client on URI '" + uri + "'. " + ex);
    }

    stream->Close();
} catch (Exception ex) {
    Console::WriteLine("Unable to connect to URI '" + uri + "'. " + ex);
}

Exceptions

ExceptionCondition
Quanser.Communications..::.StreamException If an error occurs then an exception is thrown. This situation typically arises if the stream was already closed prior to calling Close()()().

See Also