perl socket problem
Results 1 to 2 of 2

Thread: perl socket problem

  1. #1
    Junior Member
    Join Date
    Nov 2003
    Posts
    3

    perl socket problem

    Hi,

    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?

    #!/usr/bin/perl

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

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

    my $i;

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

    my $host = '169.254.99.45';

    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);

    connect(Socket_Handle,$sin);

    print "create socket\n";

    $sel->add(\*Socket_Handle);

    }



    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
    ---*NSQidy*---

  2. #2
    Senior Member
    Join Date
    Nov 2003
    Posts
    247
    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.
    www.ADigitalPimp.com
    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
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides