IO::Socket::INET Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kardon33
    New Member
    • May 2007
    • 158

    IO::Socket::INET Problem

    Currently i am working on a project to send a UDP packet through the ArtNet protocol and receive a message back and read and output it. right now i can send the message fine and the device i send it to responds but i cant read the packet and out put the datagram. My code looks like this:

    Code:
    #!/usr/bin/perl
    print "Content-type:text/html\n\n";
    
    use IO::Socket;
    #use strict;
    
    my $ID = 'Art-Net';
    my $space =' ';
    my $Prover = chr(0x0e);
    my $filler = chr(0x00);
    my $ttm = chr(0x02);
    my $pad_len_18 = 18;
    my $pad_len_64 = 64;
    my $pad_len_34 = 34;
    
    #---------------ArtPollReply Buffer--------------------------------------------------
    my $ID = $ID.$filler;
    my $OpCode = $filler.'!';
    my $IP = chr(0x02).chr(0x00).chr(0x00).chr(0x02);
    my $Port = chr(0x36).chr(0x19);
    my $vers = chr(0x02).chr(0x04);
    my $subsw = chr(0x00).chr(0x00);
    my $oem = chr(0x02).chr(0x10);
    my $UBEA = chr(0x00);
    my $status = chr(0xd2);
    my $ESTA = chr(0x4c).chr(0x41);
    
    my $short_name = 'Test';
    my $long_name = 'Test Node 1';
    my $report = 'Node is working.';
    
    $short_name = $short_name.$filler x ( $pad_len_18 - length( $short_name ) );
    $short_name = $short_name.$filler x ( $pad_len_18 - length( $short_name ) );
    	
    $long_name = $long_name.$filler x ( $pad_len_64 - length( $long_name ) );
    $long_name = $long_name.$filler x ( $pad_len_64 - length( $long_name ) );
    
    $report = $report.$filler x ( $pad_len_64 - length( $report ) );
    $report = $report.$filler x ( $pad_len_64 - length( $report ) );
    
    my $numport = chr(0x00).chr(0x08);
    my $port_type = chr(0xc0).chr(0xc0).chr(0xc0).chr(0xc0);
    my $imput_status = chr(0x80).chr(0x80).chr(0x80).chr(0x80);
    my $output_status = chr(0x80).chr(0x80).chr(0x80).chr(0x80);
    my $imput_switch = chr(0x10).chr(0x11).chr(0x12).chr(0x13);
    my $output_switch = chr(0x00).chr(0x01).chr(0x02).chr(0x03);
    my $swvideo = chr(0x00);
    my $swmacro = chr(0x55);
    my $swremote = chr(0xaa);
    my $spare = chr(0x00).chr(0x00).chr(0x00).chr(0x00);
    my $MAC = chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00);
    #----------------------------------------------------------------------------------
    	
    #-------ArtPoll-------	
    my $ArtPoll = $ID.$filler.$space.$filler.$Prover.$ttm.$filler;
    #-------ArtPollReply----
    my $ArtPollReply = $ID.$filler.'!'.$IP.$Port.$vers.$subsw.$oem.$UBEA.
    		$status.$ESTA.$short_name.$long_name.$report.$numport.$port_type.$imput_status.$output_status.
    		$imput_switch.$output_switch.$swvideo.$swmacro.$swremote.$spare.$MAC.$filler.$filler;
    #-----------------------
    
    my $response = IO::Socket::INET->new(
    	Proto => "udp",
    	PeerPort => "6454"
    );
    
    
    my $poll = IO::Socket::INET->new(
    	PeerAddr=> "2.255.255.255",
    	PeerPort => "6454",
    	Proto => "udp",
    	LocalPort => "6454"
    );
    
    
    sub ArtPoll {
    	$poll->send($ArtPoll);
    	print "ArtPoll sent.\n";
    }
    
    sub ArtPollReply {
    	$response->recv($ArtPollReply,250);
    }
    
    &ArtPoll;
    &ArtPollReply;
    
    
    print "<hr>";
    
    if ($ArtPollReply != null) {
    	print "ArtPollReply: ",$ArtPollReply;
    } else {
    	print "No data received.";
    };
    
    print "<hr>";
    print $poll,"<br>";
    print $response;
    Last edited by miller; May 11 '07, 01:32 AM. Reason: Code Tag and ReFormatting
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    your script has a few errors (or the code you posted does anyway) and should not even compile. Use the "warnings" pragma to help diagnose the problems.

    use warnings;

    The run the script from the command line and reade list of warnings/errors your code generates.

    "my" variable $ID masks earlier declaration in same scope at script line 17.
    Bareword found where operator expected at script line 58, near "$nump ort"
    (Missing operator before ort?)
    Unquoted string "ort" may clash with future reserved word at script line 58.
    Bareword found where operator expected at script line 59, near "$sw remote"
    (Missing operator before remote?)
    Unquoted string "remote" may clash with future reserved word at script line 59.
    Unquoted string "null" may clash with future reserved word at script line 86.
    syntax error at script line 58, near "$nump ort"

    Comment

    • kardon33
      New Member
      • May 2007
      • 158

      #3
      I got all those warning fixed but i still have my original problem. So if anyone can help me please do, Thank you.

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        OK, post your current code.

        Comment

        • kardon33
          New Member
          • May 2007
          • 158

          #5
          Code:
          #!/usr/bin/perl
          print "Content-type:text/html\n\n";
          
          use IO::Socket;
          #use strict;
          
          my $header = 'Art-Net';
          my $space =' ';
          my $Prover = chr(0x0e);
          my $filler = chr(0x00);
          my $ttm = chr(0x02);
          my $pad_len_18 = 18;
          my $pad_len_64 = 64;
          my $pad_len_34 = 34;
          
          #---------------ArtPollReply Buffer--------------------------------------------------
          my $ID = $header.$filler;
          my $OpCode = $filler.'!';
          my $IP = chr(0x02).chr(0x00).chr(0x00).chr(0x02);
          my $Port = chr(0x36).chr(0x19);
          my $vers = chr(0x02).chr(0x04);
          my $subsw = chr(0x00).chr(0x00);
          my $oem = chr(0x02).chr(0x10);
          my $UBEA = chr(0x00);
          my $status = chr(0xd2);
          my $ESTA = chr(0x4c).chr(0x41);
          
          my $short_name = 'Test';
          my $long_name = 'Test Node 1';
          my $report = 'Node is working.';
          
          $short_name = $short_name.$filler x ( $pad_len_18 - length( $short_name ) );
          $short_name = $short_name.$filler x ( $pad_len_18 - length( $short_name ) );
          
          $long_name = $long_name.$filler x ( $pad_len_64 - length( $long_name ) );
          $long_name = $long_name.$filler x ( $pad_len_64 - length( $long_name ) );
          
          $report = $report.$filler x ( $pad_len_64 - length( $report ) );
          $report = $report.$filler x ( $pad_len_64 - length( $report ) );
          
          my $numport = chr(0x00).chr(0x08);
          my $port_type = chr(0xc0).chr(0xc0).chr(0xc0).chr(0xc0);
          my $imput_status = chr(0x80).chr(0x80).chr(0x80).chr(0x80);
          my $output_status = chr(0x80).chr(0x80).chr(0x80).chr(0x80);
          my $imput_switch = chr(0x10).chr(0x11).chr(0x12).chr(0x13);
          my $output_switch = chr(0x00).chr(0x01).chr(0x02).chr(0x03);
          my $swvideo = chr(0x00);
          my $swmacro = chr(0x55);
          my $swremote = chr(0xaa);
          my $spare = chr(0x00).chr(0x00).chr(0x00).chr(0x00);
          my $MAC = chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00);
          #----------------------------------------------------------------------------------
          
          #-------ArtPoll-------
          my $ArtPoll = $ID.$filler.$space.$filler.$Prover.$ttm.$filler;
          #-------ArtPollReply----
          my $ArtPollReply = $ID.$filler.'!'.$IP.$Port.$vers.$subsw.$oem.$UBEA.
          	$status.$ESTA.$short_name.$long_name.$report.$nump ort.$port_type.$imput_status.$output_status.
          	$imput_switch.$output_switch.$swvideo.$swmacro.$sw remote.$spare.$MAC.$filler.$filler;
          #-----------------------
          
          my $response = IO::Socket::INET->new(
          	Proto => "udp",
          	PeerPort => "6454",
          );
          
          
          my $poll = IO::Socket::INET->new(
          	PeerAddr=> "2.255.255.255",
          	PeerPort => "6454",
          	Proto => "udp",
          	LocalPort => "6454",
          );
          
          sub ArtPoll {
          	$poll->send($ArtPoll);
          	print "ArtPoll sent.\n";
          }
          
          sub ArtPollReply {
          	$response->recv($ArtPollReply,250);
          }
          
          &ArtPoll;
          &ArtPollReply;
          Last edited by miller; May 11 '07, 01:34 AM. Reason: Code Tag and ReFormatting

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            can you please start using the code tags to post your code.

            I don't know if it is a copy and paste problem, but the code you posted still has errors:

            Bareword found where operator expected at script line 58, near "$nump ort"
            (Missing operator before ort?)
            Unquoted string "ort" may clash with future reserved word at script line 58.
            Bareword found where operator expected at script line 59, near "$sw remote"
            (Missing operator before remote?)
            Unquoted string "remote" may clash with future reserved word at script line 59.
            syntax error at script line 58, near "$nump ort"

            with those errors corrected, I can't determine why your script is not working.

            Comment

            • kardon33
              New Member
              • May 2007
              • 158

              #7
              Yeah those errors are just copy paste errors. But the script runs just fine except i need to receive the datagram packet that is being sent back to me that looks like the ArtPollReply buffer and i dont know if im using the recv command wrong but when it just empties out my buffer when the scipt runs.

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #8
                Sorry mate, I have little experience in this area. I just do not know what the problem could be, hopefully someone else will have a suggestion, or try asking on another forum.

                Comment

                • kardon33
                  New Member
                  • May 2007
                  • 158

                  #9
                  OK thanks but i might have the solution when i use ord() on the string it gives me the first interger as a dec how would ido that to all the intergers in the string.

                  Comment

                  Working...