stream_listen stream_poll navigation bar

Table of Contents

stream_accept

Deprecated

The Stream API MATLAB functions have been deprecated in favour of the new quanser.communications.stream class, which has support for code generation for Quanser targets. Hence, with the new stream class it is possible to run MATLAB scripts in real-time on Quanser targets, while making use of Quanser communications.

Accepts a connection from a client.

Syntax

[new_stream, would_block] = stream_accept(stream, send_buffer_size, receive_buffer_size)
[new_stream, would_block] = stream_accept(stream, buffer_size)  % use buffer size for both send and receive buffers.
[new_stream, would_block] = stream_accept(stream)               % use default buffer size of 8000.
    

Description

Accepts a connection from a client and returns a new stream for communicating with that client. The stream argument must have been created using the stream_listen function. Only listening streams can accept connections. In general, the listening stream may be used to accept more than one connection. The only exceptions are protocols which do not support multiple connections over the same communication channel at the same time, like the serial protocol.

Streams are normally blocking. For blocking streams, the stream_accept call will not return until a connection is made. For non-blocking listening streams, the stream_accept call will return immediately. However, if would_block is true then no connection was made. In this case the new_stream output is not valid and should not be used. The stream_poll function may be used with the 'accept' flag to determine when a connection is pending.

Streams maintain an internal buffer. Reading and writing from a stream reads and writes to or from this buffer. The underlying communication channel is only accessed when the buffer is empty (in the case of reads) or the buffer is full (in the case of writes). A buffer that is not full may be prematurely written to the underlying communication channel using the stream_flush function. The send_buffer_size and receive_buffer_size arguments indicate the size of this internal buffer for send and receive operations respectively.

When a connection is accepted, the new_stream output is a handle to a new stream representing the connection. This stream handle may be used to send and receive data over the connection. The listening stream is not closed and may be used to accept additional client connections.

When finished with the stream, the stream must be closed with stream_close or stream_close_all.

Parameters

stream

A listening stream created using stream_listen.

buffer_size

A scalar indicating the buffer size to use for the send and receive buffers of the new stream.

send_buffer_size

A scalar indicating the buffer size to use for the send buffer of the new stream.

receive_buffer_size

A scalar indicating the buffer size to use for the receive buffer of the new stream.

Outputs

new_stream

A handle to the connected stream for use with the other Quanser Stream functions.

would_block

A logical scalar used with non-blocking streams to indicate if a connection was not accepted, in which case would_block is true. Otherwise would_block is false. Failure to supply this second argument for non-blocking streams will result in an error. If this argument is supplied for a blocking stream then it always returns false.

Examples

client = stream_accept(stream);     % Accept a connection.
...
stream_close(client);               % Close the client stream to release resources.
stream_close(stream);               % Close the listening stream to release resources.
    

See Also

 

navigation bar