Connects to a server listening on the given URI using blocking I/O and default send and receive buffer sizes.

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

Syntax

Visual Basic (Declaration)
Public Sub Connect ( _
	uri As Uri _
)
C#
public void Connect(
	Uri uri
)
Visual C++
public:
void Connect(
	Uri^ uri
)
JavaScript
function connect(uri);

Parameters

uri
Type: System..::.Uri
The URI indicating the listening stream to which to connect.

Remarks

This method connects to a listening stream referenced by the given URI. The URI specifies the protocol, address, port and options associated with the server stream. The Stream object uses the protocol to load a protocol-specific driver. For example:

URIDescription
tcpip://remhost:17000 Connect to a remote host called 'remhost' on port 17000 using TCP/IP.
shmem://mymemory:1?bufsize=8192 Connect via a shared memory buffer to a server. Use 8K buffers by default.
pipe:mypipe?bufsize=4096 Connect via a named pipe to a server. Use 4K buffers for the pipe.

This method uses blocking I/O. Hence, it will block until the connection is made. Some protocols allow a timeout to be specified in the URI or have a default timeout such that the Connect will not block indefinitely.

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.
C# Copy Code
Stream  stream = new Stream();
Uri     uri    = new 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 New Uri("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();
Uri^     uri    = gcnew(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 the connection cannot be made then an exception is thrown. This situation typically arises if there is no server listening on the given URI.

See Also