Start of trail stream_receive_array navigation bar

Table of Contents

stream_receive

Receives an arbitrary data type from a stream.

Syntax

[values, would_block] = stream_receive(stream, template)
    

Description

This function receives data over a client stream. It attempts to receive the same data type as specified in the template argument from the communication channel.

If stream_listen or stream_connect was called with the non-blocking flag set to false (0), then this function blocks until all the data is read. If the connection has been closed gracefully then it returns an empty array only once there is no more data to receive. Otherwise it returns the value read before the connection closed. Once all the data in the stream buffer is exhausted it will return an empty array to indicate the connection has been closed. If an error occurs, then it issues an error message.

If stream_listen or stream_connect was called with the non-blocking flag set to true (1), then this function does not block. If no data is available at all then it returns would_block equal to true. In this case, the stream_poll function may be used with the 'receive' flag to determine when data becomes available. Otherwise it returns an array of the values received. It may receive fewer elements than the number of elements in the template array, but each element is treated as atomic. Hence, it will never receive part of an element from the stream.

This operation is not valid on listening streams created using stream_listen.

Parameters

stream

A stream handle returned by stream_connect or stream_accept.

template

The data type read from the stream will match the data type of this argument.

Outputs

values

The value received. For blocking streams, if this array is empty then then the connection has been closed gracefully. For non-blocking streams, would_block must also be false to indicate closure. The array may have fewer elements than the template argument if the stream is non-blocking or the connection was closed and these were the remaining elements.

would_block

Whether the function would have blocked. Always false for blocking streams.

Examples

        s.x = 0.0;
        s.y = 0.0;
        s.z = int16(0);
        value = stream_receive(stream, s);    % Receive a structure as two doubles followed by one 16-bit integer
    

See Also

 

navigation bar