Flushes the stream send buffer to the underlying communication channel.

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

Syntax

Visual Basic (Declaration)
Public Function Flush As Boolean
C#
public bool Flush()
Visual C++
public:
bool Flush()
JavaScript
function flush();

Return Value

Returns true if all the data in the buffer is flushed successfully. If some of the data could not be sent over the underlying communication channel, then false is returned for non-blocking streams. If an error occurs then a StreamException is thrown.

Remarks

This method flushes the stream buffer. It attempts to send the contents of the buffer over the communication channel, even if the buffer is not full. If an error occurs, then it throws a StreamException. If the connection is closed it is considered an error condition.

If Listen or Connect was called with the non-blocking flag set to false, then this method blocks until all the data in the buffer is sent.

If Listen or Connect was called with the non-blocking flag set to true, then this method does not block. It attempts to send all the data remaining in the stream buffer. However, if this operation would block then it returns false, even if it has already sent some of the data. In this case, the Poll(Timeout, Int32) method may be used with the Flush flag to determine when at least one more byte may be flushed. If an error occurs then a StreamException is thrown and the stream should be closed.

This method does not support two threads calling Send or Flush()()() at the same time. However, Receive may be called by another thread at the same time as Flush()()().

Examples

This code snippet shows how to flush the stream.
C# Copy Code
stream.Flush();
Visual Basic Copy Code
stream.Flush()
Visual C++ Copy Code
stream->Flush();

Exceptions

ExceptionCondition
Quanser.Communications..::.StreamException If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.

See Also