in reply to Re: Sending STDOUT to Multiple Sockets
in thread Sending STDOUT to Multiple Sockets

I've actually tried that but it was failing for some reason. I was using the IO::Scalar routines. Often it woudl say that $a was undefined. :\ I'll try again and see what i can come up with.
  • Comment on Re: Re: Sending STDOUT to Multiple Sockets

Replies are listed 'Best First'.
Re: Re: Re: Sending STDOUT to Multiple Sockets
by rapier1 (Novice) on Aug 18, 2001 at 00:00 UTC
    no good. I inserted
    tie *STDOUT, 'IO::Scalar', \$a; ...stuff... print $client $a; untie *STDOUT;
    in all of the appropriate locations and always got a warning about using an unitialized value. I think part of the problem is that the original C code (this is a wrapped C API I am using) actually uses a pointer to STDOUT instead of STDOUT proper. I don't know if this would be a significant issue but I'm starting to think it is.
      If this is a wrapped C API the odds are good that it is just getting a file descripter and issuing a print at a level that is too low for the tie mechanism to intercept.

      If that is the case, then your best solution is to have two processes, one of which is reading from the other, the other of which writes to all of the sockets. You can do this in various ways with fork, etc. (The Cookbook has this exact problem as an example.)

      UPDATE
      Alternate solution. Create a temporary file (for instance with File::Temp) and then let the code write to that, seek back to the beginning of the file, read it and write to the sockets, seek back and truncate. Not as immediate, but it solves the problem without creating a new process.