Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Nov 2003

    perl socket problem


    I try to build a scanner with Perl using non blocking sockets & select calls.

    The problem is the socket handle seems to close after reading all available datas

    Could someone explain me what's wrong with this?


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

    my $sel = new IO::Select();

    my $i;

    for ($i=0;$i<2;$i ++)

    my $host = '';

    my $port = 999;

    my $proto = getprotobyname('tcp');

    socket(Socket_Handle, PF_INET, SOCK_STREAM, $proto);

    my $sin = sockaddr_in($port,inet_aton($host));

    #non-blocking hack
    my $temp = 1;

    ioctl(Socket_Handle, 0x8004667E, \$temp);


    print "create socket\n";



    while (true)

    my $sr;

    my $sw;

    my $line;

    my @ready_r = $sel->can_read();

    foreach $sr (@ready_r)
    #print "$sr ready to read";

    my $sender = recv($sr, $line, 10, 0);

    print ($line);

    my @ready_w = $sel->can_write();

    foreach $sw (@ready_w)
    print "$sw ready to write";

    $line ="QUIT\r\n";

    #send($sw ,$line,0);

    #my @ready_e = $sel->has_exception();

    #foreach $se (@ready_e)
    # print "$se error pending";


    Another problem is the hasexception method which seems to hang on forever...

    Thanks for you help

  2. #2
    Senior Member
    Join Date
    Nov 2003
    I'm not an expert at Perl, but much of the syntax seems to be the same as C, C++, and several other languages....

    I don't see anything wrong with your code, atleast nothing that jumps out, but you might want to put the whole thing in a loop, or set in a Goto type thing so that when the data flow stops, it goes back to the beginning of the code to check for more information, and continually does this until it sees that more information is coming in.
    There is a ghost in the machine, and he is my friend.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.