Re: How do I redirect server's standard output to socket?



In article <1135841257.496274.321580@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
thisrule@xxxxxxxxx writes:
> I made two process. One is use for a socket server in remote host, the
> other is client.
> Socket server includes a big library and will be run in the background,
> and client program has GUI with Qt library.
> I want server standard output to redirect to client program.
>
> To do it I tried to use dup2() function, following
> dup2( socket_descriptor, 1 ); // standard out to socket
> dup2( sokcet_descriptor, 2 ); // standard err to socket
>
> Then, write( 1, "message\n", 8 ) works good.
> The string, "message" displayed in the client program.
> But printf( "message\n" ) does not work.

It is probably buffered.
Either tell the stdio library to force the buffer out when
needed with fflush(stdout), or tell it to always force the
buffer out when it gets to a '\n' by setting the buffering
policy with something like:
setvbuf(stdout, NULL, _IOLBF, BUFSIZ);

Note you should probably be using fdopen() after a dup2()
call if you are going to use stdio functions like printf(),
so the stdio library is properly initialised for those file
descriptors.

--
Andrew Gabriel
.



Relevant Pages

  • Re: Reading data on Aysnchronous socket server
    ... This could be because they wanted to save a buffer copy to join the ... | To test this I have a simulated client that sends 100 byte packets. ... | I have set up the socket server so that its buffer is bigger than this. ... | public static void AcceptCallback{ ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do I redirect servers standard output to socket?
    ... One is use for a socket server in remote host, ... > and client program has GUI with Qt library. ... > I want server standard output to redirect to client program. ...
    (comp.unix.solaris)
  • How do I redirect servers standard output to socket?
    ... Socket server includes a big library and will be run in the background, ... and client program has GUI with Qt library. ... I want server standard output to redirect to client program. ...
    (comp.os.linux.networking)
  • How do I redirect servers standard output to socket?
    ... Socket server includes a big library and will be run in the background, ... and client program has GUI with Qt library. ... I want server standard output to redirect to client program. ...
    (comp.unix.solaris)
  • Do I redirect stdout to opened socket?
    ... Socket server includes a big library and will be run in the background, ... and client program has GUI with Qt library. ... I want server standard output to redirect to client program. ...
    (comp.os.linux.development.apps)