Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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
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
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2015-11-26 18:44 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (705 votes), past polls