[26591] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8720 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 29 11:05:33 2005

Date: Tue, 29 Nov 2005 08:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 29 Nov 2005     Volume: 10 Number: 8720

Today's topics:
        length is 0 with unpack_socketaddr_in <snort_sam@yahoo.com>
        Not able to write using Open2 <Ashwin@DoNot@Email.com>
    Re: XML::Simple array size <daveandniki@ntlworld.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 29 Nov 2005 22:29:35 +1100
From: bsder <snort_sam@yahoo.com>
Subject: length is 0 with unpack_socketaddr_in
Message-Id: <438c3ba7@news.rivernet.com.au>

Hi,

I got the following error message when the client drops its connection 
after I pressed the Ctl-C.

Bad arg length for Socket::unpack_sockaddr_in, length is 0, should be 16 
at Echoer1.pl line 39.

Here is the Server code:
#!/usr/bin/perl

    use strict;
    use Socket;
    # forward declaration
    sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }

    my $proto = getprotobyname('tcp');
    socket(SOCK,PF_INET,SOCK_STREAM,$proto);
    my $host = INADDR_ANY;
    my $port = 7888;
    my $address = pack_sockaddr_in($port, $host);
    bind(SOCK, $address);
    while (1) {
       listen(SOCK, SOMAXCONN);
       my $hostName = inet_ntoa($host);
       logmsg "server started on port $port, $hostName";

       my $waitedpid = 0;
       my $paddr;

       sub REAPER {
           $waitedpid = wait;
           $SIG{CHLD} = \&REAPER;  # loathe sysV
           logmsg "reaped $waitedpid" . ($? ? " with exit $?" : '');
       }

       $SIG{CHLD} = \&REAPER;

       print STDOUT "Server host: $hostName\n";
       print STDOUT "Server port: $port\n";
       my $cAddress = accept(NEWSOCK,SOCK);

       my $kidpid;
       if (!defined($kidpid = fork())) {
          die "cannot fork: $!";
       }
       elsif ($kidpid == 0) { # child
          my ($cPort, $cHost) = unpack_sockaddr_in($cAddress);
          my $cHostName = inet_ntoa($cHost);
          print STDOUT "Client host: $cHostName\n";
          print STDOUT "Client port: $cPort\n";
          select(NEWSOCK); $| = 1; select(STDOUT);
          print NEWSOCK "Welcome to Code Generator.\r\n";
          do "dbm_lib.pm";
          my $dbm = new dbm_lib();
          $dbm->exec_code();
          while (my $m=<NEWSOCK>) {
             $m =~ s/\n|\r//g;
             print NEWSOCK "Server received $m\r\n";
          }
          close(NEWSOCK);
          exit;
       }
    }

Here is the client code:
#!/usr/bin/perl

    $domain = 2; # Internet domain
    $type = 1; # Sequenced, reliable, two-way connection, byte streams
    $proto = 6; # Transmission Control Protocol (TCP)
    socket(SOCK,$domain,$type,$proto);
    $host = pack('C4', 127,0,0,1); # localhost = 127.0.0.1
    $port = 1024;
    $address = pack('S n a4 x8', $domain, $port, $host);
    bind(SOCK, $address);
    print STDOUT "Client host: ",join('.',unpack('C4', $host)),"\n";
    print STDOUT "Client port: $port\n";
    $sHost = pack('C4', 127,0,0,1); # localhost = 127.0.0.1
    $sPort = 7888;
    $sAddress = pack('S n a4 x8', $domain, $sPort, $sHost);
    connect(SOCK, $sAddress);
    print STDOUT "Server host: ",join('.',unpack('C4', $sHost)),"\n";
    print STDOUT "Server port: $sPort\n";
    select(SOCK); $| = 1; select(STDOUT);
    while ($m=<SOCK>) {
       print STDOUT $m;
       $m = <STDIN>;
       print SOCK $m;
    }
    close(SOCK);
    exit;

Thanks
Sam


------------------------------

Date: Tue, 29 Nov 2005 14:36:13 GMT
From: "Ashwin" <Ashwin@DoNot@Email.com>
Subject: Not able to write using Open2
Message-Id: <xn0eablkbk03sc5000@news.europe.nokia.com>

Here is my complete code , I am trying to call a file, and then I need
to pass cirtain inputes which script asks,
I am opening with open2 and then trying to write with WRITE, I am able
to read but cannot write I mean I cannot send the input to WRITE handle
what could be wrong
TIA

use warnings;
use strict;
use IPC::Open2;
use Cwd;

my $currentdir=cwd();
my $pid;
chdir ("/source/internal/") or die "Cannot Change Directory";
$pid = open2 (\*READ,\*MY_WRITE,"BuildInternal.pl") or die;

while (<READ>)
{
  print $_;
  }

print MY_WRITE\n";

while (<READ>)
{
  print $_;
  }

close MY_WRITE;
close READ;

-- 



------------------------------

Date: Tue, 29 Nov 2005 14:01:02 +0100
From: "Dave" <daveandniki@ntlworld.com>
Subject: Re: XML::Simple array size
Message-Id: <438c5115$0$20172$8fcfb975@news.wanadoo.fr>


<robic0> wrote in message news:g5uno11r6901vv00tnpln9r35j3q4v3jfc@4ax.com...
> On Sat, 14 Feb 2004 17:58:08 -0500, Mark J Fenbers
> <Mark.Fenbers@noaa.gov> wrote:
>
>>In my sample XML file...
>>
>><main>
>>    <level1>
>>        <level2>whatever</level2>
>>        <level2>whatever</level2>
>>        <level2>whatever</level2>
>>        <level2>whatever</level2>
>>        <level2>whatever</level2>
>>         ...
>>    </level1>
>></main>
>>
>>I have an variable number of level2 tags.  Using XML::Simple, I can access 
>>the
>>value of the 4th one by something like this:
>>
>>    my $main = XMLin("myfile.xml");
>>    print $main->{level1}->{level2}->[3]->{content};
>>
>>But I really want to know how many level2 records there are.  I tried 
>>variations
>>
> Hey isn't the "$main" name take already?
> New rule, you have to give more details than "I want to count all
> animals on Noah's ark". Noah didn't coun't them for a reason....
> Unless you positively know ahead of time the structure of the xml
> in question, you can't rely on xml::simple's output structure.
> I guess thats the other question.....

Answering the OP's question. If there are a variable number <level2>
my $element_count =  @{ $main->{level1}->{level2} };
should do it (untested).
If there is only one level2 this will give an error unless you force 
XML::Simple to make it an array.




------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8720
***************************************


home help back first fref pref prev next nref lref last post