Menu

Start Socket Server

Help
Enzo
2007-02-15
2012-12-29
  • Enzo

    Enzo - 2007-02-15

    Hello again,

    what is the best method for start a Socket Server routine in
    a linux server? I need run this routine when the Linux box
    start every morning.

    Now, I use the mumps -r ^ROUTINE, but only for test purposes.

    It's posibly run as a service in xinetd?

    Thanks in advance,

    Enzo

     
    • K.S. Bhaskar

      K.S. Bhaskar - 2007-02-15

      Take a look at the VistA VA Demo Toaster posted at http://sourceforge.net/projects/worldvista to see how mumps -run GTMLNX^XWBTCPM is started up by inetd when a connection request comes in at port 9297.  Look at files /etc/services, /etc/inetd.conf and /var/VAVistADemo20060926/gtm_V5.2-000/cprs_direct.

      Regards
      -- Bhaskar

       
    • Enzo

      Enzo - 2007-02-16

      Hi Bhaskar,
      I couldn't download the file because this are too big.
      Is there any link to get it via ftp, with resume option
      for break connections?

      thanks and kind regards,

      Enzo

       
      • K.S. Bhaskar

        K.S. Bhaskar - 2007-02-16

        Enzo --

        I am sure that there are utilities to download files resuming after lost connections, but I do not know what they are.  If you send me your mailing address at bhaskar at users dot sourceforge dot net, I can mail you a CD.  However the following should cover the essentials:

        bash-2.05b# tail -6 /etc/services
        dircproxy       57000/tcp                       # Detachable IRC Proxy
        tfido           60177/tcp                       # fidonet EMSI over telnet
        fido            60179/tcp                       # fidonet EMSI over telnet

        # Locally defined - for VistA CPRS GUI
        cprs-gui        9297/tcp                        # direct connect VistA CPRS GUI
        bash-2.05b# tail -6 /etc/inetd.conf

        vboxd   stream  tcp     nowait  root    /usr/sbin/tcpd  /usr/sbin/vboxd

        # Local services - allow VistA CPRS GUI to connect
        cprs-gui        stream  tcp     nowait  dsl     /home/dsl/myVistA/gtm_V5.2-000/cprs_direct
        bash-2.05b# cat /home/dsl/myVistA/gtm_V5.2-000/cprs_direct
        #!/bin/bash
        #
        # cprs_direct - start a process to serve the CPRS Gui client

        # Set up the environment for VistA
        export HOME=/home/`whoami`
        cd `dirname $0`
        source ./env

        # Run the server for the CPRS GUI client
        cd ../tmp
        mumps -run GTMLNX^XWBTCPM
        bash-2.05b#

        Regards
        -- Bhaskar

         
        • Enzo

          Enzo - 2007-02-19

          Hello Bhaskar,

          I have modified the inetd.conf and the services files for calling
          my mumps script:

          inetd.conf:
          gtm-web        stream    tcp    nowait    gtm    /home/gtm/m_script

          services:
          gtm-web        11111/tcp  # sockets server

          m_script:
          #!/bin/bash
          gtm_dist=/usr/local/gtm
          export gtm_dist
          gtmroutines="/home/gtm/ .  $gtm_dist"
          export gtmroutines
          gtmgbldir=/home/gtm/mumps.gld
          export gtmgbldir
          PATH=$PATH:$gtm_dist
          export PATH
          EDITOR=/usr/bin/mcedit
          export EDITOR
          cd /home/gtm
          mumps -run W

          If I run this script manually, thats rules fine, but
          when I call the php script from a web page to request data through the 11111 port
          I receive the message: '%GTM-F-FORCEDHALT, Image HALTed by MUPIP STOP'
          and the mozilla hangs until the mumps process ends (KILL).

          Any idea?

          Thank you again!!

          Enzo

           
    • Enzo

      Enzo - 2007-02-19

      This routine, called via inetd, never makes the OPEN in W+8 ... why?

      The socket server routine:

      W   ;*** Socket Server ***
          N cmd,d,dat,dev,i,l,log,por,sck,tim
          K ^LOG
          S $ZTRAP="ZGOTO "_$ZLEVEL_":ERR"
          S por=11111
          S tim=30
          S log=1
          S dev="SCK$"_$J
          O dev:(ZLISTEN=por_":TCP":DELIMITER=$C(13):ATTACH="listener"):tim:"SOCKET" E  Q
          U dev
          W /LISTEN(1)
      E   ;
          U dev:(SOCKET="listener")
          F  W /WAIT(tim) Q:$KEY'=""
          S cmd=$P($KEY,"|",1),sck=$P($KEY,"|",2)
          I cmd="CONNECT" G E
          I cmd'="READ" G E
          U dev:(SOCKET=sck:EXCEPTION="G ERR")
          R dat:tim
          I $DEVICE C dev:(SOCKET=sck) D LOG("Error: $DEVICE="_$DEVICE) G E
          I $KEY'=$C(13) G E
          I log D LOG(dat)
          S cmd=$P(dat," "),dat=$P(dat," ",2,32767)
          I cmd="get" W @dat,! C dev:(SOCKET=sck) G E
          I cmd="xec" X @dat C dev:(SOCKET=sck) G E
          I cmd="do"  D @dat C dev:(SOCKET=sck) G E
          G E
      LOG(t) ;===== Login =====
          S ^LOG($H)=$G(t)
          Q
      ERR ;===== Error =====
          D LOG($ZSTATUS)
          C dev:(SOCKET=sck)
          G E

       
    • Sam Weiner

      Sam Weiner - 2007-02-19

      When started by inetd, $PRINCIPAL is set to the socket passed
      by inetd so it doesn't need to be opened though a USE to set
      up delimiters and other device parameters is.  $KEY will
      contain "ESTABLISHED|socket_handle|remote_ip_address".

      Trying to open a socket on the same port inetd is serving
      will cause interference.

      The "%GTM-F-FORCEDHALT, Image HALTed by MUPIP STOP"
      message means a SIGTERM was sent to the GT.M process.

      Sam

       
    • Enzo

      Enzo - 2007-02-20

      Hallo Sam,

      thanks for your response!
      With only 'USE' the socket, the routine works fine.

      Cheers,

      Enzo

       

Log in to post a comment.