/* * sendbuf - send a length-prefixed packet * * This routine builds a message packet in the form * * --------------------------------------- * | length | message | * --------------------------------------- * * where "length" is always exactly 4 bytes. * * * The recipient (recvbuf) can then read the first 4 bytes to * determine the length of the message waiting on the socket stream. * * * Modification history: * * 07 May 93 nfnm Initial implementation * 12 Aug 93 pjt Documentation and minor modifications * */ sendbuf: procedure parse arg socket, buffer /* * Get buffer length, make it 4 characters long, padded with zeros */ bufferlength = right(length(buffer), 4, '0') /* * Get length of whole packet (buffer plus length field), make it * 4 characters, padded with zeros */ bufferlength = right(bufferlength + length(bufferlength), 4, '0') /* * Concatenate length and buffer into a message packet */ packet = bufferlength||buffer /* * Send the message packet */ call _send socket, packet,,"" if sendrc < 0 then call error 'send' return