vasu has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I have a simple perl server that is invoked by inetd when a client connects to the specified inetd service port. The code is similar to:
#!/usr/bin/perl select(STDOUT); $|++; for ($i=0;$i<100; $i++) { print "Started application - $i\n"; } open (FH, ">> /tmp/xyz.log"); select(FH);$|++; while (<>) { print FH $_; if (/^ping/) { print "PING BACK\n"; } }
The problem is that the client sees the initial outputs but once the server starts reading it's STDIN, there is no more lines written to the client. What am I doing wrong ?

Replies are listed 'Best First'.
Re: inetd server not writing correctly to client
by jsprat (Curate) on Mar 20, 2003 at 02:45 UTC
    Let me guess - "PING BACK" gets written to /tmp/xyz.log

    Read perldoc -f select (select), and select STDOUT before the loop.

Re: inetd server not writing correctly to client
by rjray (Chaplain) on Mar 20, 2003 at 03:16 UTC

    Try removing just the select, and you'll see that it works. It is clear that you are doing the select to unbuffer the logging filehandle, but you need to either explicitly print to STDOUT, or re-select STDOUT so that print with no explicit filehandle goes there by default.

    --rjray

Re: inetd server not writing correctly to client
by vasu (Novice) on Mar 20, 2003 at 02:38 UTC
    I find that when I remove the opening of the intermediate file /tmp/xyz.log, then the server is writing to the client back ok ! Would appreciate any pointers on why opening a different file would cause the disassociation of the STDOUT to the client socket