-----Original Message-----
From: John W. Krahn [mailto:[EMAIL PROTECTED] 
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 [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.
> 
>>> 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>



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


Reply via email to