ooRexx logo
   1: /* ---------------------------------------------------------------- */
   2: /* streamclient in cooperation with streamserver can be used to     */
   3: /* redirect standard streams to other terminal windows              */
   4: /* ---------------------------------------------------------------- */
   5: /*                                                                  */
   6: /* Originally by Ruurd J. Idenburg                                  */                                                             
   7: /*                                                                  */
   8: /* No copyright, no licence, no guarantees or warrantees, be it     */
   9: /* explicit, implicit or whatever. Usage is totally and completely  */
  10: /* at the users own risk, the author shall not be liable for any    */ 
  11: /* damages whatsoever, for any reason whatsoever.                   */
  12: /*                                                                  */
  13: /* Please keep this comment block intact when modifying this code   */
  14: /* and add a note with a date and a description.                    */
  15: /*                                                                  */
  16: /* ---------------------------------------------------------------- */
  17: /*  Parameter(s):                                                   */ 
  18: /*                                                                  */
  19: /*    hostname - fully qualified or ip-address,                     */
  20: /*               use loclhost for same machine.                     */
  21: /*                                                                  */
  22: /*    port - port number to use for the socket connection.          */
  23: /*                                                                  */
  24: /*  Usage for instance to redirect trace output to a new terminal   */
  25: /*    out = .streamclient~new(localhost,726576))                    */
  26: /*    out~open(.context~name "- ooRexx Standard Output")            */
  27: /*    pdest = .traceoutput~destination(out)                         */
  28: /*                                                                  */
  29: /* ---------------------------------------------------------------- */
  30: /* 2015/04/08 - Initial version                                     */
  31: /* ---------------------------------------------------------------- */
  32: 
  33: ::class streamclient public subclass streamsocket
  34: 
  35: ::method init
  36:   use strict arg hostname, port, bufsize = 4096
  37:   -- pass arguments on to super class
  38:   self~init:super(hostname, port, bufsize)
  39:   -- check if streamserver is already running
  40:   socket = .socket~new('AF_INET', 'SOCK_STREAM', 0)
  41:   rc = socket~connect(.inetaddress~new(hostname,port))
  42:   -- negative return code will start the streamserver.
  43:   -- obviously, this will only work on localhost, NOT for a remote hostname
  44:   -- and only on Windows, NOT on Linux etc. For those cases start the 
  45:   -- streamserver manually before using streamclient.
  46:   if rc<0 then do
  47:     parse source os .
  48:     if os~pos("Windows")>0 & hostname=="localhost"
  49:       then address CMD 'start rexxpaws streamserver.rex' hostname port
  50:       else do
  51:         socket~close
  52:         raise syntax 93.900 array ("Could not connect to" hostname":"port"!")
  53:       end
  54:   end
  55:   -- close the socket anyway
  56:   socket~close
  57: 
  58:  
  59: ::method open
  60:   use strict arg header = ''
  61:   self~open:super
  62:   self~say(header~center(80,'='))
  63: 
  64: ::requires 'streamsocket.cls'
If you feel inclined to make corrections, suggestions etc., please mail me any.
All content © Ruurd Idenburg, 2007–, except where marked otherwise. All rights reserved. This page is primarily for non-commercial use only. The Idenburg website records no personal information and sets no ‘cookies’. This site is hosted on a VPS(Virtual Private System) rented from Transip.nl, a Dutch company, falling under Dutch (privacy) laws (I think).

This page updated on by Ruurd Idenburg.