Perl 5.8 threads and sockets problem

abez abez at abez.ca
Sun Feb 23 20:38:16 CST 2003


First of all try threads->create, rather than new. Other than that I'm too
dizzy to really help right now (flu).

On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote:

>
> Hello all,
>
> I am new to the group.
> I have a problem involving sockets and threads.
>
> Basically, I want to be able to do two or more pop3 sessions simultaniously
> using a list of different pop3 accounts.
> my problem is, I can logon to the first account, but when
> it comes to the second account's turn (in the second thread), the socket
> cannot be created.
>
> I am new to using threads and have little knowledge of sockets.
>
> Your Help is much appreciated,
>
> Thanks,
>
> Jeremy A.
>
> Below is my test script I am having trouble with.
>
>
> #-----------------------------------------------------
> use threads;
> use Win32;
> use IO::Socket qw(:DEFAULT :crlf);
>
>
> my @thr;
> my @Data;
> $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => "110",
> 'LOGIN' => "account1", 'PASS' => "******" };
> $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' => "110",
> 'LOGIN' => "account2", 'PASS' => "*****" };
> my $i = 0;
>
> sub Startup {
>     while (1) {
>       Win32::Sleep(4000);
>         foreach my $account (@Data)
>         {
>                 if(!open(T,"".$account->{'UID'}.".acc"))
>                 {
>   		Win32::Sleep(40);
>   		if($i != 0)
>   		{
>   		 $i = $i + 1;
>   		}
>   		$thr[$i] =
> threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account->{'PORT'},$account->{'LOGIN'},$account->{'PASS'});
> 		$thr[$i]->join;
>                 }else
>                 {
>                         close(T);
>                 }
>                 $i = $i - 1;
>
>         }
>   }
>   @AC = -1;
> }
>
> Startup();
>
>
>
> sub go($$$$$) {
> print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n";
>
> my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => "$_[1]",
> PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]);
> open(X,">".$_[1].".acc");
> close(X);
> print "in $_[1]\n";
> sleep(1);
> pop3close($pop3C);
> $pop3C = undef;
> unlink($_[1].".acc");
> }
>
>
> sub pop3CError ($$) {
>
> print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n";
> exit;
>
> }
>
>
> sub pop3close ($) {
> 	if ($_[0]) {
> 	 shutdown ($_[0], 2);
> 	}
> }
> #-----------------------------------------------------
>
>
>
>
>
> _________________________________________________________________
> The new MSN 8: smart spam protection and 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>

-- 
abez ------------------------------------------
http://www.abez.ca/ Abram Hindle (abez at abez.ca)
------------------------------------------ abez



More information about the Victoria-pm mailing list