Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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; }

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://727593]
Approved by ikegami
[Corion]: You'll have to look somewhere esoteric for that. Maybe some tied variable or special dualvar can also trigger that. But it's certainly not a common occurrence
[Corion]: And on 5.20, the following also outputs no find:perl -wle 'for my $x ("\x{2000}".."\ x{1fffff}") { if( $x && ! length $x ) { warn qq(<$x>); warn length $x; die } }'
[Corion]: (this time on Unix)
[hippo]: Understood. I'll have to go through the code and see if it's doing anything fancy with ties, dual-vars or non-scalars. In the end, it's probably a bug though.
[Corion]: Aaah - you should be able to do this with overload, but I would hit somebody really hard if they constructed objects that are true but the empty string, and you not knowing about the domain knowledge where this makes sense

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (14)
As of 2017-07-27 13:34 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (413 votes). Check out past polls.