C H A P T E R 2 3
Using the Endpoint Interface
Do not call the
methods in a polling loop to
look for incoming data. The Newton communications architecture
requires a return to the main event loop in order to process
incoming data from the endpoint's underlying communication
tool. These methods are included as an alternate way of retrieving
data from the incoming data buffer, not as a way to implement
synchronous data receives.
To flush data from the input buffer, you can use the methods
method discards all data in the input buffer,
discards all data read by the last call to the
Streaming Data In and Out
, there is another type of endpoint proto called
. The purpose of this streaming endpoint is to
provide a way to send and receive large frames without having first to flatten or
Flattening refers to the process of converting a frame object into a stream of bytes.
Unflattening refers to the process of converting those bytes back into a frame object.
With the streaming endpoint, frame data is flattened or unflattened in chunks as it is
sent or received. This allows large objects to be sent and received without causing
the NewtonScript heap to overflow as a result of having to convert an entire object
proto is based on
and includes a method,
, that allows you to receive streamed data. This
method automatically unflattens received data into a frame object in memory, and
can place embedded virtual binary objects directly on a store. Another method,
, allows you to send frame data as a byte stream. Note that these two
methods are synchronous; that is, they don't return until the operation is complete.
However, they do provide progress information during the operation by means of a
Working With Binary Data
For receiving binary data, the data is returned as a raw byte stream. The data is not
converted and is block-moved directly into a binary object that you have
preallocated and specified as the target for the input.
To create this target object, specify a
frame in your input spec. This frame
slot and optionally an
slot contains the
preallocated binary (or virtual binary) object, while the
slot is the offset