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

My pc runs Windows 7 Ultimate retail edition ActivePerl 5.10.1 Build 1006 interpreter but i got a problem. Multiplexing doesn't seem to work properly on Windows but it does work on Linux Ubuntu. How can i modify my script in order to run on Windows?

Replies are listed 'Best First'.
Re: Multiplexing problem
by rcaputo (Chaplain) on Feb 07, 2010 at 20:39 UTC

    My knee-jerk guess is that he's trying to multiplex non-socket filehandles, like disk or console handles. Strawberry and ActivePerl's select() on Windows are built atop winsock, so they only multiplex sockets.

    Cygwin and I think MingWin emulate select() differently, so they should work better.

    Unless I guessed totally wrong, of course.

Re: Multiplexing problem
by BrowserUk (Patriarch) on Feb 07, 2010 at 20:11 UTC
    Multiplexing doesn't seem to work properly ...

    Multiplexing what?

    Do you have some code to demonstrate your problem?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Multiplexing problem
by zentara (Cardinal) on Feb 08, 2010 at 12:09 UTC
      It would be simpler to sockify STDIN. Create a socket pair, and have a thread dump STDIN into one end of the pair. The other end is used in lieu of STDIN in the main thread.
        how can i do that?
        How can he use pipes to his advance?
      Here is my code:
      ---server--- use IO::Socket::INET; use IO::Select; $socket=new IO::Socket::INET->new(LocalPort=>2010,Proto=>'udp'); $select=IO::Select->new($socket,\*STDIN); LOOP: while(1) { @readers=$select->can_read(); foreach $ready (@readers) { if($ready eq \*STDIN) { print "\n","Enter message to send to client : "; $msg_out=<STDIN>; $socket->send($msg_out); goto LOOP; } elsif($ready eq $socket) { $socket->recv($msg_in,100); print "\n","Peer>",$msg_in; goto LOOP; } } } exit 1; ---client--- use IO::Socket::INET; use IO::Select; $socket=new IO::Socket::INET->new(PeerPort=>2010,Proto=>'udp',PeerAddr +=>'localhost'); $select=IO::Select->new($socket,\*STDIN); LOOP: while(1) { @readers=$select->can_read(); foreach $ready (@readers) { if($ready eq \*STDIN) { print "Enter message to send to server : "; $msg_out=<STDIN>; $socket->send($msg_out); goto LOOP; } elsif($ready eq $socket) { $socket->recv($msg_in,100); print "\n","Peer>",$msg_in; goto LOOP; } } } exit 1;

        STDIN is not a socket. You can only use select on sockets in Windows, as previously stated.

        Even if you weren't on Windows, it would be defy the purpose of select to read until you got a newline, and it doesn't make sense to use buffered I/O and select on the same handle.

Re: Multiplexing problem
by AriSoft (Sexton) on Feb 08, 2010 at 02:16 UTC

    Do you mean problems with IO::select ? It blocks socket if there is greater than zero timeout.