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;
Comment