Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: BGUTCP

BGUTCP.m

Go to the documentation of this file.
  1. BGUTCP ; IHS/OIT/MJL - Primary Control TCP listener ;
  1. ;;1.5;BGU;;MAY 26, 2005
  1. ;;Primary TCP Utility to start and stop Listener
  1. ;;BGUTSKT is the Socket port number for listening
  1. ;;
  1. EN ;EP-- entry point for interactive use
  1. N X1,X2,BGUTDBG S:'$D(DTIME) DTIME=300
  1. D EN^DDIOL("Enter client address: ") R X1:DTIME Q:'$T Q:X1="^"
  1. D EN^DDIOL(" Enter client port: ") R X2:DTIME Q:'$T Q:X2="^"
  1. S BGUTDBG=""
  1. D EN^BGUTCPH(X1,X2)
  1. Q
  1. STRT(BGUTSKT) D EN^DDIOL("Start TCP Listener...") ;EP--entry point for starting listener
  1. S U="^" D HOME^%ZIS
  1. STRTEN ;EP-- entry point for starting from startup
  1. I $G(BGUTSKT)="" S BGUTSKT=$G(^BGUSP(1,2),8000) ;default port
  1. ; -- see if 'running flag' for listener is set
  1. L +^BGUSP("TMP","RUNNING"):1
  1. I '$T D EN^DDIOL("TCP Listener appears to be running already.") Q
  1. L -^BGUSP("TMP","RUNNING"):1
  1. ;
  1. ; -- set stop flag to false and start the listener
  1. S ^BGUSP("TMP","STOP")=""
  1. ;D GETENV^%ZOSV
  1. ; -- START listener
  1. D
  1. .J EN^BGUTCPL(BGUTSKT)::5
  1. I '$T D EN^DDIOL("Unable to run TCP Listener in background.") Q
  1. D EN^DDIOL("TCP Listener started successfully.")
  1. Q
  1. ;
  1. STOAP(BGUTSKT) D EN^DDIOL("Stop TCP Listener...") ;EP--entry point for stoping listener
  1. ;
  1. I $G(BGUTSKT)="" S BGUTSKT=8000 ;default port
  1. ; -- make sure the listener is running
  1. L +^BGUSP("TMP","RUNNING"):1
  1. I $T D Q
  1. . L -^BGUSP("TMP","RUNNING"):1
  1. . D EN^DDIOL("TCP Listener does not appear to be running.")
  1. ;
  1. ; -- set the stop flag
  1. S ^BGUSP("TMP","STOP")=1
  1. ;
  1. ; -- send the shutdown message to the TCP Listener process
  1. S BGUVER=$G(^%ZOSF("OS")) S:'$L(BGUVER) BGUVER=$ZV
  1. S BGUMSM=$S(BGUVER["MSM":1,1:0)
  1. I BGUMSM D
  1. .O 56 U 56::"TCP"
  1. .W /SOCKET("127.0.0.1",BGUTSKT) ; -- connect to this machine
  1. .W $C(11),"TCPshutdown",! ; -- send the shutdown message
  1. .R X#3:5 ; -- get the three char 'ack' back
  1. .C 56
  1. I 'BGUMSM D
  1. .D CALL^%ZISTCP("127.0.0.1",BGUTSKT)
  1. .U IO
  1. .W $C(11),"TCPshutdown",! ; -- send the shutdown message
  1. .R X#3:5 ; -- get the three char 'ack' back
  1. .;C IO
  1. .;D CLOSE^%ZISTCP
  1. D EN^DDIOL("TCP Listener has been shutdown.")
  1. Q
  1. ;
  1. STOP(BGUTSKT) ;EP--entry point for stop TCP Listener. Interactive and TaskMan entry point
  1. STPEN ;EP -- entry point for stopping from option
  1. I $G(BGUTSKT)="" S BGUTSKT=$G(^BGUSP(1,2),8000) ;default port
  1. ;N IP,REF,X,DEV,XWBOS,XWBIP
  1. S U="^" D HOME^%ZIS
  1. D EN^DDIOL("Stop TCP Listener...")
  1. X ^%ZOSF("UCI") S REF=Y
  1. S IP="0.0.0.0" ;get server IP
  1. S XWBOS=$S(^%ZOSF("OS")["DSM":"DSM",^("OS")["MSM":"MSM",^("OS")["OpenM":"OpenM",1:"") ;RWF
  1. ;
  1. I $G(BGUTSKT)="" S BGUTSKT=8000 ;default port
  1. ; -- make sure the listener is running
  1. L +^BGUSP("TMP","RUNNING"):1
  1. I $T D Q
  1. . L -^BGUSP("TMP","RUNNING"):1
  1. . D EN^DDIOL("TCP Listener does not appear to be running.")
  1. ;
  1. ; -- set the stop flag
  1. S ^BGUSP("TMP","STOP")=1
  1. ;
  1. ; -- send the shutdown message to the TCP Listener process
  1. ; using loopback address
  1. S XWBTSKT=BGUTSKT
  1. S XWBIP="127.0.0.1"
  1. D CALL^%ZISTCP("127.0.0.1",XWBTSKT) I POP D Q
  1. . D EN^DDIOL("TCP Listener does not appear to be running.")
  1. U IO
  1. ;
  1. W $C(11),"TCPshutdown",! ; -- send the shutdown message
  1. R X#3:5
  1. D EN^DDIOL("TCP Listener Response to Shutdown Request: "_X)
  1. D CLOSE^%ZISTCP
  1. IF X="ack" D EN^DDIOL("TCP Listener has been shutdown.")
  1. ELSE D EN^DDIOL("Shutdown Failed!")
  1. ;change process name
  1. ;D CHPRN^XWBTCPC($J)
  1. Q
  1. RESTART(BGUTSKT) ;STOPS AND STARTS LISTENER
  1. D STOP(BGUTSKT)
  1. H 2
  1. D STRT(BGUTSKT)
  1. Q