C H A P T E R 2 3
Endpoint Interface
Using the Endpoint Interface
23-11
When you are finished with an endpoint, you must unbind it using the
UnBind
method, then dispose of it using the
Dispose
method.
Establishing a Connection
23
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
Connect
method. If the physical connection is serial, for instance, you don't even need to
specify an address as an option. The
Connect
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
'address
in order to make a connection.
The modem tool requires a phone number as an
'address
option. You should
use the global function
MakePhoneOption
to return a proper phone number
'address
option. The AppleTalk tool requires an AppleTalk Name Binding
Protocol (NBP)
'address
option. You should use the global function
MakeAppleTalkOption
to return a proper NBP
'address
option.
To establish a connection where you expect someone else to initiate the connection,
you need to call the
Listen
method. Once the connection is made by using
Listen
, you need to call the
Accept
method to accept the connection, or the
Disconnect
method to reject the connection and disconnect.
Sending Data
23
To send data, use the
Output
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
Output
method.
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
sendFlags
slot in the output spec
frame. In this slot, you specify one or more flag constants added together.
To send packetized data, you set
sendFlags
to
kPacket+kMore
for each packet
of data that is not the last packet. For the last packet, set
sendFlags
to
kPacket+kEOP
.