C H A P T E R 2 3
Using the Endpoint Interface
When you are finished with an endpoint, you must unbind it using the
method, then dispose of it using the
Establishing a Connection
After instantiating and binding an endpoint, you establish a connection.
There are two ways you can create a connection. One way is to call the
method. If the physical connection is serial, for instance, you don't even need to
specify an address as an option. The
method immediately establishes
communication with whatever is at the other end of the line.
Certain communication tools--for example, the modem and AppleTalk tools--
require you to specify an option of type
in order to make a connection.
The modem tool requires a phone number as an
option. You should
use the global function
to return a proper phone number
option. The AppleTalk tool requires an AppleTalk Name Binding
option. You should use the global function
to return a proper NBP
To establish a connection where you expect someone else to initiate the connection,
you need to call the
method. Once the connection is made by using
, you need to call the
method to accept the connection, or the
method to reject the connection and disconnect.
To send data, use the
method. This method is intelligent enough to figure
out the type of data you're sending and to convert it appropriately for transmission.
This is because NewtonScript objects have type information embedded in their
values, allowing the system to select appropriate default data forms for different
kinds of data being sent.
You can specify output options and a callback method by defining an output spec,
which you pass as a parameter to the
Certain communication tools may require or support the use of special flags
indicating that particular protocols are in use. For example, the built-in infrared and
AppleTalk tools expect framed (or packetized) data, and there are special flags to
indicate that this kind of protocol is in use. If you are using such a communication
tool to send data, you need to specify the
slot in the output spec
frame. In this slot, you specify one or more flag constants added together.
To send packetized data, you set
for each packet
of data that is not the last packet. For the last packet, set