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

This page updated on Wed, 28 May 2025 10:38:18 +0200.