Hi Andre Muench -
  
At 2005-11-19, 18:55:13 you wrote:
>Hi,
>
>I have a Problem with blocking INET reading. I created a socket and wait 
>till a client connect to it. But no matter what I do, whenever I try to 
>read from the socket, it blocks. I tried $Client->blocking(0), but it 
>seems to have no effect. I tested it under Win2000 with Perl 5.6.1. Does 
>anyone kown how I can solve this problem?
>
>Code:
>
>$Socket = IO::Socket::INET->new(
>                                        LocalPort => '25022',
>                                        Proto => 'tcp',
>                                        Listen => 10,
>                                        Timeout => 1,
>                                        Type => SOCK_STREAM,
>                                        Reuse => 1
>                                        ) or die $!;
>
>until($Client = $Socket->accept()) {}
>
>
>$Client->blocking(0);
># The next statment shouldnt block, but it does !!!
>$Input = <$Client>;
>$Client->blocking(1);
>
>Later in the program I need the blocking. Has this anything to do with 
>Perl or Windows Version, I have problems with sockets under Win NT 4.0 
>too, but on the Client side ( but this is another story ).
>
>Andre
>

See if IO::Select works for you. The following example is straight
from the IO::Select manpage - I haven't tried to see if it applies to
your problem or not:

"Here is a short example which shows how IO::Select could be used to write a 
server which communicates with several sockets while also listening for more 
connections on a listen socket

    use IO::Select;
    use IO::Socket;

    $lsn = new IO::Socket::INET(Listen => 1, LocalPort => 8080);
    $sel = new IO::Select( $lsn );

    while(@ready = $sel->can_read) {
        foreach $fh (@ready) {
            if($fh == $lsn) {
                # Create a new socket
                $new = $lsn->accept;
                $sel->add($new);
            }
            else {
                # Process socket

                # Maybe we have finished with the socket
                $sel->remove($fh);
                $fh->close;
                            }
                        }
                    }
"
                        
Aloha => Beau;
[EMAIL PROTECTED]
2005-11-20



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to