$title('nssndmsg - send a message using the nameserver to locate the socket') $compact nssndmsg: DO; $include(:rmx:inc/rmxplm.ext) $include(dcom.ext) $include (dcom.lit) $include(:rmx:inc/error.lit) $include(err.ext) $include(nserv.ext) $include(nclient.lit) $include(nstabl.lit) /******************************************************************** * * MODULE NAME: nssndmsg * * DESCRIPTION: This module and nsrcvmsg demonstrate the use of the * nameserver. Send a request to the nameserver for the * receiver's socket. Then send a simple message to the * receiver. * *********************************************************************/ DECLARE /* Literals */ CONBUF LITERALLY '16', /* size of a control buffer */ NOEXCEPT LITERALLY '0', /* no exception handling by system */ TIMETOWAIT LITERALLY '0100H', /* time to wait for response from server */ SFLAGS LITERALLY '00000B'; /* data buffer, synchronous flags*/ DECLARE /* Global vars */ status WORD, port_t TOKEN, /* Token for local port */ msock DWORD, /* socket to which message is sent */ con_buf (CONBUF) BYTE, /* control buffer */ mess_size DWORD, /* number of bytes in data message */ bpool TOKEN, /* buffer pool attached to port */ trans_id WORD, /* transaction id */ server_host_id WORD, /* host id of nameserver */ result BYTE, /* result of requested operation */ mes_buf(*) BYTE INITIAL (26,'This is a simple message',0dh,0ah); CALL set$exception(NOEXCEPT); port_t = get$dport(0, @bpool, CHAIN, @status); server_host_id = get_host_id(TIMETOWAIT, @status); IF server_host_id = SERVERNOTFOUND THEN DO; CALL rq$csend$co$response(NIL, 0, @(25,'Remote Server Not Found',0dh,0ah), @status); CALL rq$exit$io$job(0,NIL,@status); END; result = get_socket(server_host_id, @(8,'receiver'), @msock, TIMETOWAIT, @status); CALL error$check(510, status); IF result = REQCOMPLETED THEN DO; mess_size = size(mes_buf); trans_id = rq$send(port_t,msock, @con_buf, @mes_buf, mess_size, SFLAGS, @status); CALL error$check(520, status); END; ELSE IF result = NOTEXIST THEN DO; CALL rq$csend$co$response(NIL, 0, @(18,'Socket Not Found',0dh,0ah), @status); CALL rq$exit$io$job(0,NIL,@status); END; ELSE CALL error$check(530, status); CALL rq$exit$io$job(0,NIL,@status); END nssndmsg;