Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Problem in socket

by nagalenoj (Friar)
on Dec 03, 2008 at 05:54 UTC ( #727593=perlquestion: print w/ replies, xml ) Need Help??
nagalenoj has asked for the wisdom of the Perl Monks concerning the following question:

Dear friends,

I have written a simple client-server program. As, I need multiplexing, I used select function. When the server's fd is ready to read, I accept the new clients. Fortunately, Every thing is working fine.

After accepting the client, I am printing a message, "New client connected". The print is not working.

I checked the /proc/<pid>/fd directory, to check whether the STDOUT is closed. But, the stdout is opened.

The code piece, print "Before select\n"; # It is getting printed. while (1) { # used select my $count = select($rout = $rin, undef, undef, 0.001); next if($count <= 0); foreach (keys %client_hash) { if(vec($rout, $_, 1) == 1) { # if server then accept if($_ == fileno($SERVER)) { my $paddr = accept(my $Client,$SERVER); $client_hash{fileno($Client)} = $Client; $client_hash_values{fileno($Client)} = $paddr; print "New Client Connected\n" ; vec($rin, fileno($Client), 1) = 1; next; }

Comment on Problem in socket
Download Code
Re: Problem in socket
by ikegami (Pope) on Dec 03, 2008 at 07:05 UTC

    ( Nevermind, its probably not buffering. The "by the way" still applies, though )

    I don't you flushing the output. Suffering from Buffering?

    By the way, use IO::Select instead of using select. It's much more readable.

      Enable the autoflash, which might help you.
      $| = 1;
Re: Problem in socket
by zentara (Archbishop) on Dec 03, 2008 at 13:38 UTC
    I checked the /proc/<pid>/fd directory, to check whether the STDOUT is closed. But, the stdout is opened.

    STDOUT may be opened, but not selected, maybe try print STDOUT "New Client Connected\n" ;


    I'm not really a human, but I play one on earth Remember How Lucky You Are

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://727593]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-07-23 08:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (137 votes), past polls