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

Hello All, I have the below code that accepts connections from web browsers fine. But, with a telnet net connection it hangs till I hit a key stroke, then it begins to print the hello out forever which is perfect.

What I would like to know is how can I get it to not wait for the keystroke from a telnet connections, but to begin printing right away.

Please help I am lost and need to figure this out today!!



use IO::Socket; use IO::Select; $server_port=2000; $timeout=0; $|=0; $server = IO::Socket::INET->new( LocalPort => $server_port, Type => SOCK_STREAM, Reuse => 1, Listen => 10, ) or die "Couldn't be a tcp server on port $server_port : $@\n"; $select=IO::Select->new($server); while(1){ foreach my $client ($select->can_read($timeout)){ if($client == $server){ $client=$server->accept(); $client->autoflush(0); $select->add($client); } else{ $wBuffer="hello"; $ew=syswrite($client,$wBuffer); print "Ew = $ew\n"; #$select->remove($client); } } }

Replies are listed 'Best First'.
Re: Telnet Help
by ambrus (Abbot) on Jul 07, 2004 at 23:49 UTC

    I'm not really sure but I guess you should check this line:

    foreach my $client ($select->can_read($timeout))

    You iterate only those connections from which you can_read, so it's no surprise that it does not iterate on a connection fron which you have not received data.

      Well I have tried that but it is not the problem. By all standards, I do believe the problem is laying with how select is dealing with the connection.

      For if I just remove anything to due wiht select and just accept and start to writing to the socket it works just fine.

      Hopefully someone can see a glitch in there as it in theory should be working.
Re: Telnet Help
by Anonymous Monk on Jul 08, 2004 at 20:39 UTC
    Okay I am still lost on this..
Re: Telnet Help
by Anonymous Monk on Jul 07, 2004 at 23:14 UTC
    Could someone point me to the right place to look?