Connects to a server listening on the given URI using blocking I/O.
Namespace:
Quanser.CommunicationsAssembly: Quanser.Communications (in Quanser.Communications.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Sub Connect ( _ uri As Uri, _ sendBufferSize As Integer, _ receiveBufferSize As Integer _ ) |
C# |
---|
public void Connect( Uri uri, int sendBufferSize, int receiveBufferSize ) |
Visual C++ |
---|
public: void Connect( Uri^ uri, int sendBufferSize, int receiveBufferSize ) |
JavaScript |
---|
function connect(uri, sendBufferSize, receiveBufferSize); |
Parameters
- uri
- Type: System..::.Uri
The URI indicating the listening stream to which to connect.
- sendBufferSize
- Type: System..::.Int32
The size of the buffer to use for sending data over the stream, in bytes. This buffer is referred to as the stream send buffer in this documentation.
- receiveBufferSize
- Type: System..::.Int32
The size of the buffer to use for receiveing data over the stream, in bytes. This buffer is referred to as the stream receive buffer in this documentation.
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:
URI | Description |
---|---|
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.
C# | Copy Code |
---|---|
Stream stream = new Stream(); Uri uri = new Uri("tcpip://localhost:18000"); int sendBufferSize = 1024; int receiveBufferSize = 1024; bool done = false; try { stream.Connect(uri, sendBufferSize, receiveBufferSize); 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 sendBufferSize As Integer = 1024 Dim receiveBufferSize As Integer = 1024 Dim done As Boolean = False Try stream.Connect(uri, sendBufferSize, receiveBufferSize) 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 Uri(L"tcpip://localhost:18000"); int sendBufferSize = 1024; int receiveBufferSize = 1024; bool done = false; try { stream->Connect(uri, sendBufferSize, receiveBufferSize); 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
Exception | Condition |
---|---|
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. |