The primary class used for communications.

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

Syntax

Visual Basic (Declaration)
Public Class Stream
C#
public class Stream
Visual C++
public ref class Stream
JavaScript
Quanser.Communications.Stream = function();

Type.createClass(
	'Quanser.Communications.Stream');

Remarks

The Stream class is the starting point for communications using the Quanser .NET Class Library. Begin by creating a Stream object using the default constructor. Then to establish a connection with a local or remote server use one of the Connect methods. To act as a server, use one of the Listen methods to establish a listening connection, and then use the Accept method to accept a connection from a local or remote client.

The Stream class looks deceptively like a TCP/IP socket class. However, it is far more powerful. All the communications protocols supported by QUARC are available through the same API: TCP/IP, UDP, serial, shared memory, pipes, files and more. This flexibility is accomplished through the use of Universal Resource Identifiers or URIs. The Stream API uses URIs to identify the communications protocol and associated parameters, such as hostname, port, baud rate, stop bits, etc. Refer to Universal Resource Identifers for more information.

Each Stream object maintains two circular "stream" buffers: one of received data and one for data to be sent. These internal buffers are called the "stream receive buffer" and the "stream send buffer" respectively. These buffers enable the Stream object to receive multi-byte data types, such as doubles, or arrays, without the user needing to worry about receiving only some of the bytes within the data type, but not all. Similarly, these same data types can be sent without worrying about only some of the bytes being transmitted but not all.

These buffers also allow more efficient communications to be performed since large chunks of data may be received at a time, even if the user is only requesting a small number of bytes. Likewise, data can be accumulated in the stream send buffer before actually writing it to the underlying communication channel so that optimal use is made of packets in a packet-based communication protocol.

Finally, the stream send and receive buffers allow the Stream class to change the endianness of the incoming or outgoing data according to the data types being transferred, so that communications between peers with differing endianness can readily be supported.

Communications under the Quanser .NET Class Library may be categorized into several categories:

CategoryDescription
Configuration Methods The configuration methods are used to establish a client or server connection and to set or retrieve various properties of that connection.
Reception Methods The reception methods are used to receive data in binary or textual format from the peer.
Transmission Methods The transmission methods are used to send data in binary or textual format to the peer.

The configuration methods are:

Method NameDescription
Listen(String) Establish a listening server connection using a String for the URI. The connection uses blocking I/O.
Listen(Uri) Establish a listening server connection using a Uri for the URI. The connection uses blocking I/O.
Listen(String, Boolean) Establish a listening server connection using a String for the URI. The connection uses blocking or non-blocking I/O.
Listen(Uri, Boolean) Establish a listening server connection using a Uri for the URI. The connection uses blocking or non-blocking I/O.
Connect(String) Connect as a client to a peer using a String for the URI. The connection uses blocking I/O and default buffer sizes.
Connect(Uri) Connect as a client to a peer using a Uri for the URI. The connection uses blocking I/O and default buffer sizes.
Connect(String, Int32, Int32) Connect as a client to a peer using a String for the URI. The connection uses blocking I/O.
Connect(Uri, Int32, Int32) Connect as a client to a peer using a Uri for the URI. The connection uses blocking I/O.
Connect(String, Boolean, Int32, Int32) Connect as a client to a peer using a String for the URI. The connection uses blocking or non-blocking I/O.
Connect(Uri, Boolean, Int32, Int32) Connect as a client to a peer using a Uri for the URI. The connection uses blocking or non-blocking I/O.
Accept(Int32, Int32) Accept a connection from a client on a listening connection.
Accept()()() Accept a connection from a client on a listening connection.
Poll(Timeout, Int32) Waits for a specified time interval for an event on the stream, such as the reception of data or space in the transmit buffer.
SetSwapBytes(Boolean) Configure the stream to swap the bytes within binary data types to account for differing endianness between the two endpoints.
SetByteOrder(Stream..::.ByteOrder) Configure the byte ordering used by the stream for sending and receiving binary data types to account for differing endianness between the two endpoints.
SetCharacterFormat(Stream..::.CharacterFormat) Set the characters used when communicating in textual format.
GetCharacterFormat()()() Get the current character format for the stream.
Shutdown()()() Shuts down the stream gracefully, without actually closing the stream.
Close()()() Closes the stream.
CloseAll()()() Closes all streams currently connected or listening.

The reception methods are:

Method NameDescription
Receive(array<SByte>[]()[]) Receives an array of 8-bit integers. Fewer integers may be received than requested for non-blocking streams.
Receive(array<Int16>[]()[]) Receives an array of 16-bit integers. Fewer integers may be received than requested for non-blocking streams.
Receive(array<Int32>[]()[]) Receives an array of 32-bit integers. Fewer integers may be received than requested for non-blocking streams.
Receive(array<Int64>[]()[]) Receives an array of 64-bit integers. Fewer integers may be received than requested for non-blocking streams.
Receive(array<Single>[]()[]) Receives an array of 32-bit floating-point values. Fewer values may be received than requested for non-blocking streams.
Receive(array<Double>[]()[]) Receives an array of 64-bit floating-point values. Fewer values may be received than requested for non-blocking streams.
ReceiveArray(array<SByte>[]()[]) Receives an array of 8-bit integers as an atomic unit. Either the entire array will be received, or none of it, for non-blocking streams.
ReceiveArray(array<Int16>[]()[]) Receives an array of 16-bit integers as an atomic unit. Either the entire array will be received, or none of it, for non-blocking streams.
ReceiveArray(array<Int32>[]()[]) Receives an array of 32-bit integers as an atomic unit. Either the entire array will be received, or none of it, for non-blocking streams.
ReceiveArray(array<Int64>[]()[]) Receives an array of 64-bit integers as an atomic unit. Either the entire array will be received, or none of it, for non-blocking streams.
ReceiveArray(array<Single>[]()[]) Receives an array of 32-bit floating-point values as an atomic unit. Either the entire array will be received, or none of it, for non-blocking streams.
ReceiveArray(array<Double>[]()[]) Receives an array of 64-bit floating-point values as an atomic unit. Either the entire array will be received, or none of it, for non-blocking streams.
Ignore(Int32) Receive but ignore a specified number of bytes from the stream.

The transmission methods are:

Method NameDescription
Send(array<SByte>[]()[]) Sends an array of 8-bit integers. Fewer integers may be sent than requested for non-blocking streams.
Send(array<Int16>[]()[]) Sends an array of 16-bit integers. Fewer integers may be sent than requested for non-blocking streams.
Send(array<Int32>[]()[]) Sends an array of 32-bit integers. Fewer integers may be sent than requested for non-blocking streams.
Send(array<Int64>[]()[]) Sends an array of 64-bit integers. Fewer integers may be sent than requested for non-blocking streams.
Send(array<Single>[]()[]) Sends an array of 32-bit floating-point values. Fewer values may be sent than requested for non-blocking streams.
Send(array<Double>[]()[]) Sends an array of 64-bit floating-point values. Fewer values may be sent than requested for non-blocking streams.
SendArray(array<SByte>[]()[]) Sends an array of 8-bit integers as an atomic unit. Either the entire array will be sent, or none of it, for non-blocking streams.
SendArray(array<Int16>[]()[]) Sends an array of 16-bit integers as an atomic unit. Either the entire array will be sent, or none of it, for non-blocking streams.
SendArray(array<Int32>[]()[]) Sends an array of 32-bit integers as an atomic unit. Either the entire array will be sent, or none of it, for non-blocking streams.
SendArray(array<Int64>[]()[]) Sends an array of 64-bit integers as an atomic unit. Either the entire array will be sent, or none of it, for non-blocking streams.
SendArray(array<Single>[]()[]) Sends an array of 32-bit floating-point values as an atomic unit. Either the entire array will be sent, or none of it, for non-blocking streams.
SendArray(array<Double>[]()[]) Sends an array of 64-bit floating-point values as an atomic unit. Either the entire array will be sent, or none of it, for non-blocking streams.
Flush()()() Flush the contents of the stream buffer to the underlying communications channel so that data remaining in the buffer is sent.

Inheritance Hierarchy

System..::.Object
  Quanser.Communications..::.Stream

See Also