FAQ
Hi All!

I'm pretty new to working with sockets in perl, looked around for days
for a proper solution for my IRC/DCC problem but couldn't find one.

The connection to the server uses a socket with a neverending while
loop:

sub connection {
# Make The Initial Server Connection! #
$con = IO::Socket::INET->new(PeerAddr=>"$server",
PeerPort=>"$port",
Proto=>'tcp',
Timeout=>'30') || print "Error! $!\n";

while($answer = <$con>) {

<http://www.perlmonks.org/?abspart=1;displaytype=displaycode;node_id=718
388;part=1>

All works fine untill i want to make a DCC connection using another
socket:
$dcc = IO::Socket::INET->new(PeerAddr=>"$2",
PeerPort=>"$3",
Proto=>'tcp',
Timeout=>'30') || print "Error! $!\n";
print $dcc "Connection Established!\n";
while ($talk = <$dcc>) {

<http://www.perlmonks.org/?abspart=1;displaytype=displaycode;node_id=718
388;part=2>

The first loop is being blocked?
I only receive input/output from the second loop untill this one is
closed again, then the first loop continues....
How can i get a continuous flow from both?
I've read some bits about IO::Socket::Select, and have also been playing
with multiple threads, but i prefer the first option... Any help is very
appreciated!


-
Marco van Kammen
Springer
System Manager & Postmaster
-
Van Godewijckstraat 30 | 3311 GX
Office Number: 05E21
P.O. Box 17 | 3300 AA
Dordrecht | The Netherlands
tel +31 (0) 78 657 6446
fax +31 (0) 78 657 6302
Marco.vanKammen@springer.com
www.springer.com <http://www.springer.com/>
-

Search Discussions

  • Zentara at Oct 21, 2008 at 11:57 am

    On Tue, 21 Oct 2008 12:53:53 +0200, Marco.vanKammen@springer.com ("Kammen van, Marco, Springer SBM NL") wrote:

    Hi All!

    I'm pretty new to working with sockets in perl, looked around for days
    for a proper solution for my IRC/DCC problem but couldn't find one.

    The connection to the server uses a socket with a neverending while
    loop:
    All works fine untill i want to make a DCC connection using another
    socket:
    The first loop is being blocked?
    I only receive input/output from the second loop untill this one is
    closed again, then the first loop continues....
    How can i get a continuous flow from both?
    I've read some bits about IO::Socket::Select, and have also been playing
    with multiple threads, but i prefer the first option... Any help is very
    appreciated!
    Marco van Kammen
    You need to use select, or put a timeout on can_read on both sockets.

    See the following for how to use timeouts:
    http://perlmonks.org?node_id=716603

    http://perlmonks.org?node_id=602621


    Here is an example of a server using select. You can
    search google and groups.google.com for "perl select socket"
    for many, many more examples.

    #!/usr/bin/perl
    use Net::hostent;
    use IO::Socket::INET;
    use IO::Select;

    my $s = new IO::Select;

    $IP = '192.168.0.1';
    $PORT = 15005;

    my $server = new IO::Socket::INET(
    LocalAddr => $IP,
    LocalPort => $PORT,
    Proto => 'tcp',
    Listen => SOMAXCONN,
    ReuseAddr => 1
    );


    # Listen for multiple connections.
    $s->add($server);
    $s->add(\*STDIN);
    print ">> $0 accepting connections on $PORT\n";

    while ( my @ready = $s->can_read() ) {
    foreach my $fh (@ready) {

    #if($fh == \*STDIN){ $in_text = <>;
    # foreach my $fh (@ready){ print "$in_ip >> $in_text";}
    # }


    if ( $fh == $server ) {
    my $new = $server->accept;
    $s->add($new);
    my $hostinfo = inet_ntoa( $new->peeraddr );

    # Show IP that just connected.
    print "CONN >> $hostinfo\n";
    }
    else {

    #my $in_ip = inet_ntoa($fh->peeraddr);#error-prone
    my $in_ip = $fh->peeraddr ? inet_ntoa( $fh->peeraddr ) : "unknown";
    my $in_text = scalar <$fh>;

    # If the client closes the connection, remove this socket, but
    #keep the script running, waiting/serving other connections.
    if ( $in_text ne "" ) { }
    else {
    $s->remove($fh);
    $fh->close;
    print "DISCONN >> $in_ip\n";
    }

    # Every time "TEXT\n" is sent, display this
    print "$in_ip >> $in_text";
    }
    }
    }

    print "Program end.\n";
    __END__



    zentara
  • Kammen van, Marco, Springer SBM NL at Oct 21, 2008 at 2:01 pm

    Hi All!

    I'm pretty new to working with sockets in perl, looked around for days
    for a proper solution for my IRC/DCC problem but couldn't find one.

    The connection to the server uses a socket with a neverending while
    loop:
    All works fine untill i want to make a DCC connection using another
    socket:
    The first loop is being blocked?
    I only receive input/output from the second loop untill this one is
    closed again, then the first loop continues....
    How can i get a continuous flow from both?
    I've read some bits about IO::Socket::Select, and have also been playing
    with multiple threads, but i prefer the first option... Any help is very
    appreciated!
    Marco van Kammen
    You need to use select, or put a timeout on can_read on both sockets.
    See the following for how to use timeouts:
    http://perlmonks.org?node_id=716603
    zentara
    Thanks for your input....
    The whole select thingie is still a bit blurry to me...(I really need a
    Book).

    Which I forgot to mention is that both my sockets are connected to
    different ports... (54321 & 1024)
    And also, one socket is connected to a server, and the other socket is
    accepting from a client....
    Does this change anything??

    So Loop 1 is reading stuff that is happening on the server.
    And Loop 2 is reading stuff that a direct client is sending.

    Marco!
  • Bob McConnell at Oct 21, 2008 at 2:42 pm
    From: Kammen van, Marco, Springer SBM NL
    Hi All!

    I'm pretty new to working with sockets in perl, looked around for days
    for a proper solution for my IRC/DCC problem but couldn't find one.

    The connection to the server uses a socket with a neverending while
    loop:
    All works fine untill i want to make a DCC connection using another
    socket:
    The first loop is being blocked?
    I only receive input/output from the second loop untill this one is
    closed again, then the first loop continues....
    How can i get a continuous flow from both?
    I've read some bits about IO::Socket::Select, and have also been playing
    with multiple threads, but i prefer the first option... Any help is very
    appreciated!
    You need to use select, or put a timeout on can_read on both sockets.
    See the following for how to use timeouts:
    http://perlmonks.org?node_id=716603
    zentara
    Thanks for your input....
    The whole select thingie is still a bit blurry to me...(I really need a
    Book).

    Which I forgot to mention is that both my sockets are connected to
    different ports... (54321 & 1024)
    And also, one socket is connected to a server, and the other socket is
    accepting from a client....
    Does this change anything??

    So Loop 1 is reading stuff that is happening on the server.
    And Loop 2 is reading stuff that a direct client is sending.

    Marco!

    At this level, the only difference between a client and a server is the
    opening sequence. After the sockets are open, they can be treated
    exactly the same.

    So once you have the sockets open, and as long as there are no pending
    listens for additional connections, there are no differences in how you
    read or write on multiple sockets. You need a single loop where select
    will return when one or both sockets have received data, when it times
    out or when a signal is received, whichever comes first. The timeout can
    be used to check for other events, like keyboard input, before you loop
    back into the select call.

    Bob McConnell
  • Kammen van, Marco, Springer SBM NL at Oct 22, 2008 at 6:47 am
    -----Original Message-----
    From: Bob McConnell
    Which I forgot to mention is that both my sockets are connected to
    different ports... (54321 & 1024)
    And also, one socket is connected to a server, and the other socket is
    accepting from a client....
    Does this change anything??

    So Loop 1 is reading stuff that is happening on the server.
    And Loop 2 is reading stuff that a direct client is sending.

    Marco!
    At this level, the only difference between a client and a server is
    the
    opening sequence. After the sockets are open, they can be treated
    exactly the same.
    So once you have the sockets open, and as long as there are no pending
    listens for additional connections, there are no differences in how
    you
    read or write on multiple sockets. You need a single loop where select
    will return when one or both sockets have received data, when it times
    out or when a signal is received, whichever comes first. The timeout
    can
    be used to check for other events, like keyboard input, before you
    loop
    back into the select call.
    Bob McConnell

    Thanks Bob, that makes things a bit more clear.
    So say that I have <$socket1> and <$socket2>....
    How can I read from both using one loop then??

    Marco!
  • Zentara at Oct 22, 2008 at 12:27 pm

    On Wed, 22 Oct 2008 08:47:13 +0200, Marco.vanKammen@springer.com ("Kammen van, Marco, Springer SBM NL") wrote:

    At this level, the only difference between a client and a server is
    the
    opening sequence. After the sockets are open, they can be treated
    exactly the same.
    So once you have the sockets open, and as long as there are no pending
    listens for additional connections, there are no differences in how
    you
    read or write on multiple sockets. You need a single loop where select
    will return when one or both sockets have received data, when it times
    out or when a signal is received, whichever comes first. The timeout
    can
    be used to check for other events, like keyboard input, before you
    loop
    back into the select call.
    Bob McConnell

    Thanks Bob, that makes things a bit more clear.
    So say that I have <$socket1> and <$socket2>....
    How can I read from both using one loop then??

    Marco!
    Google and groups.google.com are loaded with examples.
    Learn to search for keywords like "perl socket timeout".

    You really should bite the bullet, and learn to use select, it is more
    efficient than timeouts in a loop. But you may try something like
    (read perldoc IO::Socket)


    while(1){

    if( $socket1->connected ){
    $socket1->timeout(.01);
    my data = sysread ($socket1, my $buf, 1024);
    print "$buf\n";
    }else{ close $socket1 }

    if( $socket2->connected ){
    $socket2->timeout(.01);
    my data = sysread ($socket2, my $buf, 1024);
    print "$buf\n";
    }else{ close $socket2 }

    # etc etc etc
    }


    but select will handle it better, and is not that hard to learn.

    See: http://www.cs.uno.edu/~golden/teach.html
    and look for the Perl examples for a basic tutorial on sockets.


    zentara
  • Peter Scott at Oct 22, 2008 at 12:01 pm

    On Tue, 21 Oct 2008 12:53:53 +0200, Kammen van, Marco, Springer SBM NL wrote:
    I'm pretty new to working with sockets in perl, looked around for days
    for a proper solution for my IRC/DCC problem but couldn't find one.
    If you'd like to do this without grubbing around at the socket level,
    check out POE on CPAN and the POE::Component::IRC modules.
  • Kammen van, Marco, Springer SBM NL at Oct 22, 2008 at 12:05 pm

    From: Peter Scott
    Subject: Re: Reading from multiple sockets.
    On Tue, 21 Oct 2008 12:53:53 +0200, Kammen van, Marco, Springer SBM NL
    wrote:
    I'm pretty new to working with sockets in perl, looked around for days
    for a proper solution for my IRC/DCC problem but couldn't find one.
    If you'd like to do this without grubbing around at the socket level,
    check out POE on CPAN and the POE::Component::IRC modules.
    --
    Peter Scott
    Thanks Peter..

    But I do want to fiddle around with sockets and stuff, complicated or
    not... Everyone needs to learn sometime right? :-D
    And I want to keep the number of additional modules as minimal as
    possible...
    I know this means more coding, but that doesn't matter... Its all good
    learning experience...

    Marco.
  • John W. Krahn at Oct 22, 2008 at 12:51 pm

    Kammen van, Marco, Springer SBM NL wrote:
    From: Peter Scott
    Subject: Re: Reading from multiple sockets.
    On Tue, 21 Oct 2008 12:53:53 +0200, Kammen van, Marco, Springer SBM NL
    wrote:
    I'm pretty new to working with sockets in perl, looked around for days
    for a proper solution for my IRC/DCC problem but couldn't find one.
    If you'd like to do this without grubbing around at the socket level,
    check out POE on CPAN and the POE::Component::IRC modules.
    --
    Peter Scott
    Thanks Peter..

    But I do want to fiddle around with sockets and stuff, complicated or
    not... Everyone needs to learn sometime right? :-D
    And I want to keep the number of additional modules as minimal as
    possible...
    I know this means more coding, but that doesn't matter... Its all good
    learning experience...
    Then you should probably get the book _UNIX Network Programming_ and/or
    _Network Programming with Perl_.



    John
    --
    Perl isn't a toolbox, but a small machine shop where you
    can special-order certain sorts of tools at low cost and
    in short order. -- Larry Wall
  • Kammen van, Marco, Springer SBM NL at Oct 23, 2008 at 9:00 am
    -----Original Message-----
    From: John W. Krahn
    Sent: Wednesday, October 22, 2008 2:51 PM
    To: Perl Beginners
    Subject: Re: Reading from multiple sockets.

    Kammen van, Marco, Springer SBM NL wrote:
    From: Peter Scott
    Subject: Re: Reading from multiple sockets.
    On Tue, 21 Oct 2008 12:53:53 +0200, Kammen van, Marco, Springer SBM
    NL
    wrote:
    I'm pretty new to working with sockets in perl, looked around for
    days
    for a proper solution for my IRC/DCC problem but couldn't find one.
    If you'd like to do this without grubbing around at the socket
    level,
    check out POE on CPAN and the POE::Component::IRC modules.
    --
    Peter Scott
    Thanks Peter..

    But I do want to fiddle around with sockets and stuff, complicated or
    not... Everyone needs to learn sometime right? :-D
    And I want to keep the number of additional modules as minimal as
    possible...
    I know this means more coding, but that doesn't matter... Its all good
    learning experience...
    Then you should probably get the book _UNIX Network Programming_
    and/or
    _Network Programming with Perl_.
    John
    Yeah I was planning to add another Perl programming book to my list....
    Thanks for all hints so far... I've got the following to work now using
    IO::Select
    Properly send & receive to and from server.
    I can esablish a DCC connection over additional socket, but then I only
    get the data from the DCC socket, and no-longer the data from the server
    socket, untill the DCC socket is closed.....



    <code snip>
    $con = IO::Socket::INET->new(PeerAddr=>"$server",
    PeerPort=>"$port",
    Proto=>'tcp',
    Timeout=>'30') || print "Error! $!\n";
    $select = IO::Select->new($con);

    while(@ready = $select->can_write) {
    for $socket (@ready) {
    #The DCC Connection
    if($socket == $dcc) {
    $talk = <$dcc>;
    print $talk;
    #The Server Connection
    } elsif ($socket == $con) {
    $answer = <$con>;
    print $answer; # echo everything that comes from the server to
    screen
    #lots of other stuff here
    if ($answer =~ /:(.*)\!.* PRIVMSG $me :\001DCC CHAT chat (\d+)
    (\d+)\001\r\n/) {
    print "Received dcc from $1 with $2 and $3\n";
    $dcc = IO::Socket::INET->new(PeerAddr=>"$2",
    PeerPort=>"$3",
    Proto=>'tcp',
    Timeout=>'30') || print "Error!
    $!\n";
    print $dcc "Please Enter Your Password!\n";
    $select = IO::Select->new($dcc);
    }
    } else {
    print "more stuff to come here"
    }
    }
    }
    </code snip>
  • Kammen van, Marco, Springer SBM NL at Oct 23, 2008 at 12:35 pm

    Kammen van, Marco, Springer SBM NL wrote:
    From: Peter Scott
    Subject: Re: Reading from multiple sockets.
    On Tue, 21 Oct 2008 12:53:53 +0200, Kammen van, Marco, Springer SBM
    NL
    wrote:
    I'm pretty new to working with sockets in perl, looked around for
    days
    for a proper solution for my IRC/DCC problem but couldn't find one.
    Yeah I was planning to add another Perl programming book to my
    list....
    Thanks for all hints so far... I've got the following to work now
    using
    IO::Select
    Properly send & receive to and from server.
    I can esablish a DCC connection over additional socket, but then I
    only
    get the data from the DCC socket, and no-longer the data from the
    server
    socket, untill the DCC socket is closed.....
    Never mind... I think i fixed it....
    Dunno if its the proper way but hey it works!!!!!!!!!

    $con = IO::Socket::INET->new(PeerAddr=>"$server",
    PeerPort=>"$port",
    Proto=>'tcp',
    Timeout=>'30') || print "Error! $!\n";
    $select = IO::Select->new();
    $select->add($con);
    while(@ready = $select->can_write) {
    for $socket (@ready) {
    #The DCC Connection
    if($socket == $dcc) {
    $talk = <$dcc>;
    print $talk;
    #The Server Connection
    } elsif ($socket == $con) {
    $answer = <$con>;
    print $answer;
    # Stufff
    if ($answer =~ /:(.*)\!.* PRIVMSG $me :\001DCC CHAT chat (\d+) (
    +\d+)\001\r\n/) {
    print "Received dcc from $1 with $2 and $3\n";
    $dcc = IO::Socket::INET->new(PeerAddr=>"$2",
    PeerPort=>"$3",
    Proto=>'tcp',
    Timeout=>'30') || print "Error!
    + $!\n";
    print $dcc "Please Enter Your Password!\n";
    $select->add($dcc);
    }
    } else {
    print "Dunno?\n";
    exit 1;
    }
    }
    }




    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    http://learn.perl.org/
  • Kammen van, Marco, Springer SBM NL at Oct 30, 2008 at 7:33 am

    From: Peter Scott
    Subject: Re: Reading from multiple sockets.
    On Tue, 21 Oct 2008 12:53:53 +0200, Kammen van, Marco, Springer SBM
    NL
    wrote:
    I'm pretty new to working with sockets in perl, looked around for
    days
    for a proper solution for my IRC/DCC problem but couldn't find one.
    Yeah I was planning to add another Perl programming book to my
    list....
    Thanks for all hints so far... I've got the following to work now
    using
    IO::Select
    Properly send & receive to and from server.
    I can esablish a DCC connection over additional socket, but then I
    only
    get the data from the DCC socket, and no-longer the data from the
    server
    socket, untill the DCC socket is closed.....
    Never mind... I think i fixed it....
    Dunno if its the proper way but hey it works!!!!!!!!!
    $con = IO::Socket::INET->new(PeerAddr=>"$server",
    PeerPort=>"$port",
    Proto=>'tcp',
    Timeout=>'30') || print "Error! $!\n";
    $select = IO::Select->new();
    $select->add($con);
    while(@ready = $select->can_write) {
    for $socket (@ready) {
    #The DCC Connection
    if($socket == $dcc) {
    $talk = <$dcc>;
    print $talk;
    #The Server Connection
    } elsif ($socket == $con) {
    $answer = <$con>;
    print $answer;
    # Stufff
    if ($answer =~ /:(.*)\!.* PRIVMSG $me :\001DCC CHAT chat (\d+) (
    +\d+)\001\r\n/) {
    print "Received dcc from $1 with $2 and $3\n";
    $dcc = IO::Socket::INET->new(PeerAddr=>"$2",
    PeerPort=>"$3",
    Proto=>'tcp',
    Timeout=>'30') || print "Error!
    + $!\n";
    print $dcc "Please Enter Your Password!\n";
    $select->add($dcc);
    }
    } else {
    print "Dunno?\n";
    exit 1;
    }
    }
    }
    It looked like it worked but keep ending up in some kind of lock....
    As soon as the second socket kicks in things go wrong....
    It's a shame there are tons of pieces of code for IRC thingies, but none
    of a fully functional one including DCC connections.... (without using
    additional modules).

    Any help in the right direction is appreciated...

    (and yes I'm still waiting on my Perl networking book!)
  • kenTk at Nov 1, 2008 at 9:41 pm

    On Oct 30, 8:33 am, Marco.vanKam...@springer.com (Kammen van) wrote:
    From: Peter Scott
    Subject: Re: Reading from multiple sockets.
    On Tue, 21 Oct 2008 12:53:53 +0200, Kammen van, Marco, Springer SBM
    NL
    wrote:
    I'm pretty new to working with sockets in perl, looked around for
    days
    for a proper solution for my IRC/DCC problem but couldn't find one.
    Yeah I was planning to add another Perl programming book to my
    list....
    Thanks for all hints so far... I've got the following to work now
    using
    IO::Select
    Properly send & receive to and from server.
    I can esablish a DCC connection over additional socket, but then I
    only
    get the data from the DCC socket, and no-longer the data from the
    server
    socket, untill the DCC socket is closed.....
    Never mind... I think i fixed it....
    Dunno if its the proper way but hey it works!!!!!!!!!
    $con = IO::Socket::INET->new(PeerAddr=>"$server",
    PeerPort=>"$port",
    Proto=>'tcp',
    Timeout=>'30') || print "Error! $!\n";
    $select = IO::Select->new();
    $select->add($con);
    while(@ready = $select->can_write) {
    for $socket (@ready) {
    #The DCC Connection
    if($socket == $dcc) {
    $talk = <$dcc>;
    print $talk;
    #The Server Connection
    } elsif ($socket == $con)  {
    $answer = <$con>;
    print $answer;
    # Stufff
    if ($answer =~ /:(.*)\!.* PRIVMSG $me :\001DCC CHAT chat (\d+) (
    +\d+)\001\r\n/) {
    print "Received dcc from $1 with $2 and $3\n";
    $dcc = IO::Socket::INET->new(PeerAddr=>"$2",
    PeerPort=>"$3",
    Proto=>'tcp',
    Timeout=>'30') ||   print "Error!
    + $!\n";
    print $dcc "Please Enter Your Password!\n";
    $select->add($dcc);
    }
    } else {
    print "Dunno?\n";
    exit 1;
    }
    }
    }
    It looked like it worked but keep ending up in some kind of lock....
    As soon as the second socket kicks in things go wrong....
    It's a shame there are tons of pieces of code for IRC thingies, but none
    of a fully functional one including DCC connections.... (without using
    additional modules).

    Any help in the right direction is appreciated...

    (and yes I'm still waiting on my Perl networking book!)
    This seems to come up regularly and there seems to be little accurate
    information on Non-Blocking sockets.
    The main problem is that the Blocking=>0 option doesn't work when
    creating the object.
    You have to do it as follows:

    $con = IO::Socket::INET->new(PeerAddr=>"$server",

    PeerPort=>"$port",
    Proto=>'tcp',
    Timeout=>'30') || print "Error! $!\n";
    # for Linux
    $con->blocking(0);

    # For windoze
    my $temp = 1;
    ioctl ($con , 0x8004667E, \$temp);


    This works for both Listening (server) and client socket connections.
    You can leave both methods in the script because windoze and Linux
    don't complain.
    I have used it for multiple client and server objects running
    simultaneously.
    You simply check for connections and data from them sequentially in a
    loop.
  • Kammen van, Marco, Springer SBM NL at Nov 3, 2008 at 7:04 am
    -----Original Message-----
    From: kenTk
    Sent: Saturday, November 01, 2008 10:41 PM
    To: beginners@perl.org
    Subject: Re: Reading from multiple sockets.
    On Oct 30, 8:33 am, Marco.vanKam...@springer.com (Kammen van) wrote:
    From: Peter Scott
    Subject: Re: Reading from multiple sockets.
    On Tue, 21 Oct 2008 12:53:53 +0200, Kammen van, Marco, Springer SBM
    NL
    wrote:
    I'm pretty new to working with sockets in perl, looked around for
    days
    for a proper solution for my IRC/DCC problem but couldn't find one.
    Yeah I was planning to add another Perl programming book to my
    list....
    Thanks for all hints so far... I've got the following to work now
    using
    IO::Select
    Properly send & receive to and from server.
    I can esablish a DCC connection over additional socket, but then I
    only
    get the data from the DCC socket, and no-longer the data from the
    server
    socket, untill the DCC socket is closed.....
    Never mind... I think i fixed it....
    Dunno if its the proper way but hey it works!!!!!!!!!
    $con = IO::Socket::INET->new(PeerAddr=>"$server",
    PeerPort=>"$port",
    Proto=>'tcp',
    Timeout=>'30') || print "Error! $!\n";
    $select = IO::Select->new();
    $select->add($con);
    while(@ready = $select->can_write) {
    for $socket (@ready) {
    #The DCC Connection
    if($socket == $dcc) {
    $talk = <$dcc>;
    print $talk;
    #The Server Connection
    } elsif ($socket == $con)  {
    $answer = <$con>;
    print $answer;
    # Stufff
    if ($answer =~ /:(.*)\!.* PRIVMSG $me :\001DCC CHAT chat (\d+) (
    +\d+)\001\r\n/) {
    print "Received dcc from $1 with $2 and $3\n";
    $dcc = IO::Socket::INET->new(PeerAddr=>"$2",
    PeerPort=>"$3",
    Proto=>'tcp',
    Timeout=>'30') ||   print "Error!
    + $!\n";
    print $dcc "Please Enter Your Password!\n";
    $select->add($dcc);
    }
    } else {
    print "Dunno?\n";
    exit 1;
    }
    }
    }
    It looked like it worked but keep ending up in some kind of lock....
    As soon as the second socket kicks in things go wrong....
    It's a shame there are tons of pieces of code for IRC thingies, but none
    of a fully functional one including DCC connections.... (without using
    additional modules).

    Any help in the right direction is appreciated...

    (and yes I'm still waiting on my Perl networking book!)
    This seems to come up regularly and there seems to be little accurate
    information on Non-Blocking sockets.
    The main problem is that the Blocking=>0 option doesn't work when
    creating the object.
    You have to do it as follows:
    $con = IO::Socket::INET->new(PeerAddr=>"$server",
    PeerPort=>"$port",
    Proto=>'tcp',
    Timeout=>'30') || print "Error! $!\n";
    # for Linux
    $con->blocking(0);
    # For windoze
    my $temp = 1;
    ioctl ($con , 0x8004667E, \$temp);
    This works for both Listening (server) and client socket connections.
    You can leave both methods in the script because windoze and Linux
    Don't complain.
    have used it for multiple client and server objects running
    simultaneously.
    You simply check for connections and data from them sequentially in a
    loop.
    Hi Ken!

    Thanks for the advice......
    Added the $con->blocking(0); to both my listening and connecting sockets but still same result...
    One socket is waiting for the other one :-(

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedOct 21, '08 at 10:54a
activeNov 3, '08 at 7:04a
posts14
users6
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase