Apple Newton Internet Enabler Spezifikationen Seite 7

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 24
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 6
Newton Technology Journal June 1996
7
type: 'option,
opCode: opGetCurrent,
result: nil,
form: 'template,
data: {
arglist:
[
0, // host addr - byte 1
0, // host addr - byte 2
0, // host addr - byte 3
0, // host addr - byte 4
0, // host port number
],
typelist: kPortAddrStruct,
[
'struct,
'byte,
'byte,
'byte,
'byte,
'short
]
}
},
inputScript: func(ep, data, terminator, options)
begin
// do something with data
end,
completionScript: func(ep, options, result)
begin
// skip error handling for canceled requests
if result <> kCommAbortErr then
begin
print("Error: " && result);
ep:DoDisconnect();
end;
end,
}
try
ep:SetInputSpec(streamInputSpec);
onexception |evt.ex.comm| do
return :DoDisconnect();
The example input specification frame above tells Newton Internet
Enabler to receive a packet of data from the UDP link and provides two
scripts: the inputScript function to process normal completion of data
reception and the completionScript function to process
unexpected termination of data reception. In addition, this input spec
includes a “get” of the UDP source socket address, which will be filled in
with the IP address of the host that sent the datagram to your application.
For TCP links, you do not need to include any options or specify any
receive flags in your input specification frame. For example, the following code
segment receives a carriage return-terminated string from a TCP connection.
local streamInputSpec := {
form: 'string,
termination: {endSequence: UnicodeCR},
discardAfter: 256,
inputScript: func(ep, data, terminator, options)
begin
// do something with data
end,
completionScript: func(ep, options, result)
begin
// skip error handling for canceled requests
if result <> kCommAbortErr then
begin
print("Error: " && result);
ep:DoDisconnect();
end;
end,
}
try
ep:SetInputSpec(streamInputSpec);
onexception |evt.ex.comm| do
return :DoDisconnect();
The example input specification frame above tells Newton Internet
Enabler to terminate input upon receiving a Unicode carriage return character
and provides two scripts: the inputScript function to process normal
completion of data reception and the completionScript function to
process unexpected termination of data reception.
You can also receive expedited data over a TCP link. When expedited
data arrives, your application is immediately notified: the link controller
sends an application event frame. The eventCode slot of this event
frame has the value kEventToolSpecific and the data slot is the
byte that was received.
See the chapter “Endpoint Interface” in Newton Programmer’s Guide for
detailed information about input specifications, the SetInputSpec
method, handling communications events, and other styles of receiving data
with an endpoint.
Disconnecting Your Endpoint
When you have finished using your endpoint, you need to disconnect,
unbind, and dispose of it. The following function shows you an example of
finishing your use of an endpoint.
MyApp.DoDisconnect := func()
begin
if ep then begin // ignore all disconnect errors
try
ep:Disconnect(true, nil);
onexception |evt.ex.comm| do
nil;
try
ep:UnBind(nil)
onexception |evt.ex.comm| do
nil;
try
ep:Dispose()
onexception |evt.ex.comm| do
nil;
end;
end;
Releasing Your Link
After your application is completely done with the link, or whenever you will
not be using the link for a long period of time (approximately 15 minutes or
longer), you need to release it by calling the InetReleaseLink
function. If no other applications are using the link, the Newton system
software shuts it down.
You need to provide InetReleaseLink with a link ID, a callback
function, and a callback context frame:
InetReleaseLink(linkID, clientContext, clientCallback)
USING THE DOMAIN NAME SERVICE INTERFACE
You can use the Newton Internet Enabler domain name service functions to
translate between host name and Internet address representations. Newton
Internet Enabler provides the following domain name service global functions:
the DNSCancelRequests function cancels any pending DNS
requests.
the DNSGetAddressFromNamefunction translates a
domain name into its corresponding Internet address.
the DNSGetMailAddress function translates a domain name
into the Internet address for a mail server that serves that domain.
Seitenansicht 6
1 2 3 4 5 6 7 8 9 10 11 12 ... 23 24

Kommentare zu diesen Handbüchern

Keine Kommentare