// Sending an ALAP packet synchronously and waiting asynchronously for a
// response.
// This example uses the ALTERNATE interface
// NOTE: This code relies on a network event being delivered in order to
// terminate. The receipt of network events cannot be relied upon under
// Multifinder or System 7
// Assuming inclusion of
#include <AppleTalk.h>
#include
void myfunction (void);
void DoError (OSErr myErr); void CheckForMyEvent (void);
main ()
{
ATLAPRecHandle myABRecord;
char myBuffer[600]; // buffer for both send and
// receive
short myErr,
index,
dataLen;
if ( myErr)
DoError( myErr);
// Maybe serial port B isn't available for use by AppleTalk
else {
myABRecord = (ATLAPRecHandle) NewHandle(lapSize); myLAPType = 73;
// Enter myLAPType into protocol handler table and install default
// handler to service frames of that ALAP type. No packets of
// that ALAP type will be received until we call LAPRead. if ( myErr)
DoError ( myErr);
// Have we opened too many protocol types? Remember that DDP
// uses two of them.
else {
// Prepare data to be sent
strcpy ((char *) someText,
"This data will be in the ALAP data area");
CtoPstr (someText);
// The .MPP implementation requires that the first two bytes
// of the ALAP data field contain the length of the data,
// including the length bytes themselves.
dataLen = strlen ((char *) someText) + 2;
myBuffer[0] = dataLen / 256; // high byte of data length
myBuffer[1] = dataLen % 256; // low byte of data length
for (index = 1; index <= dataLen-2; index++)
myBuffer[index+1] = someText[index];
(* myABRecord)->lapAddress.dstNodeID = 4;
(* myABRecord)->lapDataPtr = myBuffer;
// Send the frame
// In the case of a sync call, errCode and the abResult field of
// the myABRecord will contain the same result code. We can also
// reuse myABRecord, since we know whether the call has completed.
if ( myErr)
DoError( myErr);
// Maybe the receiving node wasn't on-line
else {
// We have sent out the packet and are now waiting for a
// response. We issue an async LAPRead call so that we don't // "hang" waiting for a response that may not come.
(* myABRecord)->lapAddress.lapProtType = myLAPType;
// ALAP type we want to receive
// our buffer is maximum size
(* myABRecord)->lapDataPtr = myBuffer;
myErr = LAPRead ( myABRecord, async); // wait for a packet
if ( myErr)
DoError( myErr);
// Was the protocol handler installed correctly?
else {
// We can either sit here in a loop and poll the abResult
// field or just exit our code and use the event
// mechanism to flag us when the packet arrives.
CheckForMyEvent(); // your procedure for checking for a
// network event
if ( myErr)
DoError( myErr);
}
}
}
}
}