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.
How do I redirect server's standard output to socket?
Please let me know.
|
|
0
|
|
|
|
Reply
|
thisrule (5)
|
12/29/2005 7:27:37 AM |
|
thisrule@gmail.com wrote:
> 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.
>
> How do I redirect server's standard output to socket?
> Please let me know.
Hi,
First of all, I must say that this answer is not previously tested, nor
extracted from a direct equal experience.
Two things that could (or not) help:
a) flush stdout after "printf"?
b) Use inetd. In this way, redirection is done by the inetd daemon.
Again, and before someone says something like "do not give advice if
you do not know", these are not advices, only posible ideas.
Kind regards.
|
|
0
|
|
|
|
Reply
|
tmp123
|
12/29/2005 8:50:31 AM
|
|
In article <1135841257.496274.321580@g14g2000cwa.googlegroups.com>,
thisrule@gmail.com 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
|
|
0
|
|
|
|
Reply
|
andrew
|
12/29/2005 9:01:21 AM
|
|
|
2 Replies
1003 Views
(page loaded in 0.056 seconds)
|