home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rox.zip / roxsocks.cmd < prev    next >
OS/2 REXX Batch file  |  1994-01-05  |  3KB  |  95 lines

  1. /*------------------------------------------------------------------
  2.  * test_s.cmd :
  3.  *------------------------------------------------------------------
  4.  * 08-05-92 originally by Patrick J. Mueller
  5.  *------------------------------------------------------------------*/
  6.  
  7. if RxFuncQuery("RoxLoadFuncs") then
  8.    do
  9.    rc = RxFuncAdd("RoxLoadFuncs","Rox","RoxLoadFuncs")
  10.    rc = RoxLoadFuncs()
  11.    end
  12.  
  13. rc = RoxLoad("socket.rox")
  14.  
  15. /*------------------------------------------------------------------
  16.  * choose the port
  17.  *------------------------------------------------------------------*/
  18. port = 1923
  19.  
  20. /*------------------------------------------------------------------
  21.  * create the initial socket
  22.  *------------------------------------------------------------------*/
  23. baseSock = RoxCreate("socket")
  24.  
  25. /*------------------------------------------------------------------
  26.  * catch breaks
  27.  *------------------------------------------------------------------*/
  28. signal on halt
  29.  
  30. rc = .bindServer(baseSock,port)
  31. if (rc <> 0) then
  32.    do
  33.    say "Error on SockBind:" .errno(baseSock)
  34.    exit
  35.    end
  36.  
  37. /*------------------------------------------------------------------
  38.  * infinite loop to handle requests ...
  39.  *------------------------------------------------------------------*/
  40. do forever
  41.    say "Waiting for client"
  42.  
  43.    /*---------------------------------------------------------------
  44.     * accept a connection
  45.     *---------------------------------------------------------------*/
  46.    sock = .acceptClient(baseSock)
  47.    if (sock = "") then
  48.       do
  49.       say "Error on SockAccept:" .errno(baseSock)
  50.       rc = RoxDestroy(baseSock)
  51.       exit
  52.       end
  53.  
  54.    /*---------------------------------------------------------------
  55.     * receive line from client
  56.     *---------------------------------------------------------------*/
  57.    line = .recvLine(sock)
  58.  
  59.    say "Received:" line
  60.  
  61.    line = reverse(line)
  62.  
  63.    /*---------------------------------------------------------------
  64.     * send data back
  65.     *---------------------------------------------------------------*/
  66.    rc = .sendLine(sock,line)
  67.    if (rc = -1) then
  68.       do
  69.       say "Error on SockSend:" .errno(sock)
  70.       rc = RoxDestroy(sock)
  71.       rc = RoxDestroy(baseSock)
  72.       exit
  73.       end
  74.  
  75.    /*---------------------------------------------------------------
  76.     * close the new socket
  77.     *---------------------------------------------------------------*/
  78.    rc = RoxDestroy(sock)
  79.    sock = ""
  80. end
  81.  
  82. /*------------------------------------------------------------------
  83.  * handle break by closing sockets
  84.  *------------------------------------------------------------------*/
  85. halt:
  86.  
  87. say
  88. say "Quitting ..."
  89.  
  90. rc = RoxDestroy(baseSock)
  91.  
  92. if (sock <> "") then
  93.    rc = RoxDestroy(sock)
  94.  
  95.