On Oct 30, 8:33 am, [EMAIL PROTECTED] (Kammen van) wrote:
> >>> From: Peter Scott [mailto:[EMAIL PROTECTED]
> >>> 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.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to