home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / comms / other / rxsocket / examples / pserv.rexx < prev    next >
OS/2 REXX Batch file  |  1998-05-09  |  877b  |  38 lines

  1. /*
  2.     A simple inetd service example.
  3.     it waits for a string of max 256 char len and send it back reversed.
  4.     If the clip PSERV_LOG in equal to 1, the connection is logged.
  5. */
  6.  
  7. /* socket is number 0 */
  8. if ~IsSocket(0) then do
  9.     say "this service must be run from rxs in inedt"
  10.     exit
  11. end
  12.  
  13. /* who is it? */
  14. if ~GetSockName(0,"NAME")<0 then do
  15.     call SysLog("pserv Can't get peer info (" || errno() || ")")
  16.     exit
  17. end
  18.  
  19. if getclip("PSERV_LOG")==1 then do
  20.     /* log the connection */
  21.     msg = "pserv Connection from" name.addrAddr
  22.     if GetHostByAddr("HOST",name.addrAddr) then msg = msg  "(" || host.hostName || ")"
  23.     call SysLog(msg)
  24. end
  25.  
  26. /* the service itself */
  27. len = recv(0,"BUF",256)
  28. if len<0 then do
  29.     call SysLog("pserv Error reading (" || errno() || ")")
  30.     exit
  31. end
  32.  
  33. buf = reverse(buf)
  34. if send(0,BUF)~=length(buf) then do
  35.     call SysLog("pserv Error sending (" || errno() || ")")
  36.     exit
  37. end
  38.