home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / vrxda.zip / Server.VRX < prev    next >
Text File  |  1995-08-24  |  7KB  |  306 lines

  1. /*:VRX         Main
  2. */
  3. /*  Main
  4. */
  5. Main:
  6. /*  Process the arguments.
  7.     Get the parent window.
  8. */
  9.     parse source . calledAs .
  10.     parent = ""
  11.     argCount = arg()
  12.     argOff = 0
  13.     if( calledAs \= "COMMAND" )then do
  14.         if argCount >= 1 then do
  15.             parent = arg(1)
  16.             argCount = argCount - 1
  17.             argOff = 1
  18.         end
  19.     end; else do
  20.         call VROptions 'ImplicitNames'
  21.         call VROptions 'NoEchoQuit'
  22.     end
  23.     InitArgs.0 = argCount
  24.     if( argCount > 0 )then do i = 1 to argCount
  25.         InitArgs.i = arg( i + argOff )
  26.     end
  27.     drop calledAs argCount argOff
  28.  
  29. /*  Load the windows
  30. */
  31.     call VRInit
  32.     parse source . . spec
  33.     _VREPrimaryWindowPath = ,
  34.         VRParseFileName( spec, "dpn" ) || ".VRW"
  35.     _VREPrimaryWindow = ,
  36.         VRLoad( parent, _VREPrimaryWindowPath )
  37.     drop parent spec
  38.     if( _VREPrimaryWindow == "" )then do
  39.         call VRMessage "", "Cannot load window:" VRError(), ,
  40.             "Error!"
  41.         _VREReturnValue = 32000
  42.         signal _VRELeaveMain
  43.     end
  44.  
  45. /*  Process events
  46. */
  47.     call Init
  48.     signal on halt
  49.     do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
  50.         _VREEvent = VREvent()
  51.         interpret _VREEvent
  52.     end
  53. _VREHalt:
  54.     _VREReturnValue = Fini()
  55.     call VRDestroy _VREPrimaryWindow
  56. _VRELeaveMain:
  57.     call VRFini
  58. exit _VREReturnValue
  59.  
  60. VRLoadSecondary:
  61.     __vrlsWait = abbrev( 'WAIT', translate(arg(2)), 1 )
  62.     if __vrlsWait then do
  63.         call VRFlush
  64.     end
  65.     __vrlsHWnd = VRLoad( VRWindow(), VRWindowPath(), arg(1) )
  66.     if __vrlsHWnd = '' then signal __vrlsDone
  67.     if __vrlsWait \= 1 then signal __vrlsDone
  68.     call VRSet __vrlsHWnd, 'WindowMode', 'Modal' 
  69.     __vrlsTmp = __vrlsWindows.0
  70.     if( DataType(__vrlsTmp) \= 'NUM' ) then do
  71.         __vrlsTmp = 1
  72.     end
  73.     else do
  74.         __vrlsTmp = __vrlsTmp + 1
  75.     end
  76.     __vrlsWindows.__vrlsTmp = VRWindow( __vrlsHWnd )
  77.     __vrlsWindows.0 = __vrlsTmp
  78.     do while( VRIsValidObject( VRWindow() ) = 1 )
  79.         __vrlsEvent = VREvent()
  80.         interpret __vrlsEvent
  81.     end
  82.     __vrlsTmp = __vrlsWindows.0
  83.     __vrlsWindows.0 = __vrlsTmp - 1
  84.     call VRWindow __vrlsWindows.__vrlsTmp 
  85.     __vrlsHWnd = ''
  86. __vrlsDone:
  87. return __vrlsHWnd
  88.  
  89. /*:VRX         DC_1_ClientListen
  90. */
  91. DC_1_ClientListen: 
  92.     hConn = VRInfo( "DAHandle");
  93.     Listen = VRInfo( "Start");
  94.     if Listen then
  95.         str = hconn "Starts listening"
  96.     else
  97.         str = hconn "Stops listening"
  98.     position = VRMethod( "LB_1", "AddString", str,  )
  99.     ok = VRMethod( "DC_1", "SendData", "0", "Hello there, how are you?", 0, hconn, 0, 0);
  100. return
  101.  
  102. /*:VRX         DC_1_Connect
  103. */
  104. DC_1_Connect: 
  105.     hconn = VRInfo( "DAHandle");
  106.     str = hconn "connected"
  107.     position = VRMethod( "LB_1", "AddString", str,  )
  108.     ok = VRMethod( "DC_1", "SendData", "0", "Hello there, how are you?", 0, hconn, 0, 0);
  109. return
  110.  
  111. /*:VRX         DC_1_CSError
  112. */
  113. DC_1_CSError: 
  114.     hconn = VRInfo( "DAHandle");
  115.     errno = VRInfo( "ErrNum");
  116.     errsev = VRInfo( "ErrSev");
  117.     errstr = VRInfo( "ErrMsg");
  118.     str = hconn "error" errno '('errsev')' errstr
  119.     position = VRMethod( "LB_1", "AddString", str,  )
  120.  
  121. return
  122.  
  123. /*:VRX         DC_1_DataReady
  124. */
  125. DC_1_DataReady: 
  126.     hconn = VRInfo( "DAHandle");
  127.     rspid = VRInfo( "RespID");
  128.     com = VRInfo( "CmdID");
  129.     dta = VRInfo( "Data");
  130.     str = hconn 'sent ('com 'id' rspid')' dta
  131.     if com = 'STOP_LISTEN' then
  132.         msg = 'OK, bye for now...'
  133.     else
  134.         msg = "I got your message" rspid
  135.     ok = VRMethod( "DC_1", "SendData", com, msg, rspid, hconn, 0, 0);
  136.     position = VRMethod( "LB_1", "AddString", str,  )
  137. return
  138.  
  139. /*:VRX         DC_1_Disconnect
  140. */
  141. DC_1_Disconnect: 
  142.     hconn = VRInfo( "DAHandle");
  143.     str = hconn "disconnected"
  144.     position = VRMethod( "LB_1", "AddString", str,  )
  145. return
  146.  
  147. /*:VRX         Fini
  148. */
  149. Fini:
  150.     window = VRWindow()
  151.     call VRSet window, "Visible", 0
  152.     drop window
  153. return 0
  154.  
  155. /*:VRX         Halt
  156. */
  157. Halt:
  158.     signal _VREHalt
  159. return
  160.  
  161. /*:VRX         idm_close_Click
  162. */
  163. idm_close_Click: 
  164.     selectedstring = VRGet( "LB_1", "SelectedString" )
  165.     if selectedstring = '' then
  166.         return;
  167.     hConn = word( selectedstring, 1)
  168.     ok = VRMethod( "DC_1", "StopListen", hConn);
  169. return
  170.  
  171. /*:VRX         idm_conn_Click
  172. */
  173. idm_conn_Click: 
  174.     selectedstring = VRGet( "LB_1", "SelectedString" )
  175.     if selectedstring = '' then
  176.         return;
  177.     hConn = word( selectedstring, 1)
  178.     ok = VRMethod( "DC_1", "CloseConnection", hConn);
  179. return
  180.  
  181. /*:VRX         idm_details_Click
  182. */
  183. idm_details_Click: 
  184.     selectedstring = VRGet( "LB_1", "SelectedString" )
  185.     if selectedstring = '' then
  186.         return;
  187.     hConn = word( selectedstring, 1)
  188.     ok = VRMethod( "DC_1", "GetClientData", hConn, "ConnData.");
  189.     if ok then do
  190.         msg.0 = 3
  191.         msg.1 = 'Client Handle =' hConn
  192.         if ConnData.2 then
  193.             msg.2 = 'Client is listening'
  194.         else
  195.             msg.2 = 'Client is not listening'
  196.         msg.3 = ConnData.3
  197.  
  198.         id = VRMessageStem( VRWindow(), "msg.", "Client Connection Details", "None", , ,  )
  199.     end
  200. return
  201.  
  202. /*:VRX         idm_message_Click
  203. */
  204. idm_message_Click: 
  205.     selectedstring = VRGet( "LB_1", "SelectedString" )
  206.     if selectedstring = '' then
  207.         return;
  208.     hConn = word( selectedstring, 1)
  209.     window = VRLoadSecondary( "SW_1", "W" )
  210. return
  211.  
  212. /*:VRX         Init
  213. */
  214. Init:
  215. /*    call VRRedirectStdIO 'off'
  216. */
  217.     window = VRWindow()
  218.     call VRSet window, "Visible", 1
  219.     call VRMethod window, "Activate"
  220.     drop window
  221. return
  222.  
  223. /*:VRX         LB_1_ContextMenu
  224. */
  225. LB_1_ContextMenu: 
  226.     ok = VRMethod( "Menu1", "Popup", , , "", "" )
  227. return
  228.  
  229. /*:VRX         LB_1_DoubleClick
  230. */
  231. LB_1_DoubleClick: 
  232.     selectedstring = VRGet( "LB_1", "SelectedString" )
  233.     if selectedstring <> '' then do
  234.         hConn = word( selectedstring, 1)
  235.         ok = VRMethod( "DC_1", "SendData", "0", "Hi there" hConn, 0, hConn, 0, 0);
  236.     end
  237. return
  238.  
  239. /*:VRX         PB_1_Click
  240. */
  241. PB_1_Click: 
  242.     value = VRGet( "EF_1", "Value" )
  243.     ok = VRMethod( "DC_1", "SendData", ASYNCH, value, 0, hConn, 0, 0 );
  244.     call SW_1_Close
  245. return
  246.  
  247. /*:VRX         PB_2_Click
  248. */
  249. PB_2_Click: 
  250.     call SW_1_Close
  251. return
  252.  
  253. /*:VRX         Quit
  254. */
  255. Quit:
  256.     window = VRWindow()
  257.     call VRSet window, "Shutdown", 1
  258.     drop window
  259. return
  260.  
  261. /*:VRX         SW_1_Close
  262. */
  263. SW_1_Close: 
  264.     call SW_1_Fini
  265. return
  266.  
  267. /*:VRX         SW_1_Create
  268. */
  269. SW_1_Create: 
  270.     call SW_1_Init
  271. return
  272.  
  273. /*:VRX         SW_1_Fini
  274. */
  275. SW_1_Fini: 
  276.     window = VRInfo( "Window" )
  277.     call VRDestroy window
  278.     drop window
  279. return
  280. /*:VRX         SW_1_Init
  281. */
  282. SW_1_Init: 
  283.     window = VRInfo( "Object" )
  284.     if( \VRIsChildOf( window, "Notebook" ) ) then do
  285.         call VRMethod window, "CenterWindow"
  286.         call VRSet window, "Visible", 1
  287.         call VRMethod window, "Activate"
  288.     end
  289.     drop window
  290. return
  291.  
  292. /*:VRX         Window1_Close
  293. */
  294. Window1_Close:
  295.     call Quit
  296. return
  297.  
  298. /*:VRX         Window1_KeyPress
  299. */
  300. Window1_KeyPress: 
  301.     key = VRGet( "Window1", "keyString");
  302.     if key = '{Del}' then
  303.         ok = VRMethod( "LB_1", "Clear" )
  304. return
  305.  
  306.