469,282 Members | 2,372 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

IO::Socket::INET Problem

158 100+
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:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. print "Content-type:text/html\n\n";
  3.  
  4. use IO::Socket;
  5. #use strict;
  6.  
  7. my $ID = 'Art-Net';
  8. my $space =' ';
  9. my $Prover = chr(0x0e);
  10. my $filler = chr(0x00);
  11. my $ttm = chr(0x02);
  12. my $pad_len_18 = 18;
  13. my $pad_len_64 = 64;
  14. my $pad_len_34 = 34;
  15.  
  16. #---------------ArtPollReply Buffer--------------------------------------------------
  17. my $ID = $ID.$filler;
  18. my $OpCode = $filler.'!';
  19. my $IP = chr(0x02).chr(0x00).chr(0x00).chr(0x02);
  20. my $Port = chr(0x36).chr(0x19);
  21. my $vers = chr(0x02).chr(0x04);
  22. my $subsw = chr(0x00).chr(0x00);
  23. my $oem = chr(0x02).chr(0x10);
  24. my $UBEA = chr(0x00);
  25. my $status = chr(0xd2);
  26. my $ESTA = chr(0x4c).chr(0x41);
  27.  
  28. my $short_name = 'Test';
  29. my $long_name = 'Test Node 1';
  30. my $report = 'Node is working.';
  31.  
  32. $short_name = $short_name.$filler x ( $pad_len_18 - length( $short_name ) );
  33. $short_name = $short_name.$filler x ( $pad_len_18 - length( $short_name ) );
  34.  
  35. $long_name = $long_name.$filler x ( $pad_len_64 - length( $long_name ) );
  36. $long_name = $long_name.$filler x ( $pad_len_64 - length( $long_name ) );
  37.  
  38. $report = $report.$filler x ( $pad_len_64 - length( $report ) );
  39. $report = $report.$filler x ( $pad_len_64 - length( $report ) );
  40.  
  41. my $numport = chr(0x00).chr(0x08);
  42. my $port_type = chr(0xc0).chr(0xc0).chr(0xc0).chr(0xc0);
  43. my $imput_status = chr(0x80).chr(0x80).chr(0x80).chr(0x80);
  44. my $output_status = chr(0x80).chr(0x80).chr(0x80).chr(0x80);
  45. my $imput_switch = chr(0x10).chr(0x11).chr(0x12).chr(0x13);
  46. my $output_switch = chr(0x00).chr(0x01).chr(0x02).chr(0x03);
  47. my $swvideo = chr(0x00);
  48. my $swmacro = chr(0x55);
  49. my $swremote = chr(0xaa);
  50. my $spare = chr(0x00).chr(0x00).chr(0x00).chr(0x00);
  51. my $MAC = chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00);
  52. #----------------------------------------------------------------------------------
  53.  
  54. #-------ArtPoll-------    
  55. my $ArtPoll = $ID.$filler.$space.$filler.$Prover.$ttm.$filler;
  56. #-------ArtPollReply----
  57. my $ArtPollReply = $ID.$filler.'!'.$IP.$Port.$vers.$subsw.$oem.$UBEA.
  58.         $status.$ESTA.$short_name.$long_name.$report.$numport.$port_type.$imput_status.$output_status.
  59.         $imput_switch.$output_switch.$swvideo.$swmacro.$swremote.$spare.$MAC.$filler.$filler;
  60. #-----------------------
  61.  
  62. my $response = IO::Socket::INET->new(
  63.     Proto => "udp",
  64.     PeerPort => "6454"
  65. );
  66.  
  67.  
  68. my $poll = IO::Socket::INET->new(
  69.     PeerAddr=> "2.255.255.255",
  70.     PeerPort => "6454",
  71.     Proto => "udp",
  72.     LocalPort => "6454"
  73. );
  74.  
  75.  
  76. sub ArtPoll {
  77.     $poll->send($ArtPoll);
  78.     print "ArtPoll sent.\n";
  79. }
  80.  
  81. sub ArtPollReply {
  82.     $response->recv($ArtPollReply,250);
  83. }
  84.  
  85. &ArtPoll;
  86. &ArtPollReply;
  87.  
  88.  
  89. print "<hr>";
  90.  
  91. if ($ArtPollReply != null) {
  92.     print "ArtPollReply: ",$ArtPollReply;
  93. } else {
  94.     print "No data received.";
  95. };
  96.  
  97. print "<hr>";
  98. print $poll,"<br>";
  99. print $response;
  100.  
May 10 '07 #1
8 5365
KevinADC
4,059 Expert 2GB
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"
May 10 '07 #2
kardon33
158 100+
I got all those warning fixed but i still have my original problem. So if anyone can help me please do, Thank you.
May 10 '07 #3
KevinADC
4,059 Expert 2GB
OK, post your current code.
May 10 '07 #4
kardon33
158 100+
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. print "Content-type:text/html\n\n";
  3.  
  4. use IO::Socket;
  5. #use strict;
  6.  
  7. my $header = 'Art-Net';
  8. my $space =' ';
  9. my $Prover = chr(0x0e);
  10. my $filler = chr(0x00);
  11. my $ttm = chr(0x02);
  12. my $pad_len_18 = 18;
  13. my $pad_len_64 = 64;
  14. my $pad_len_34 = 34;
  15.  
  16. #---------------ArtPollReply Buffer--------------------------------------------------
  17. my $ID = $header.$filler;
  18. my $OpCode = $filler.'!';
  19. my $IP = chr(0x02).chr(0x00).chr(0x00).chr(0x02);
  20. my $Port = chr(0x36).chr(0x19);
  21. my $vers = chr(0x02).chr(0x04);
  22. my $subsw = chr(0x00).chr(0x00);
  23. my $oem = chr(0x02).chr(0x10);
  24. my $UBEA = chr(0x00);
  25. my $status = chr(0xd2);
  26. my $ESTA = chr(0x4c).chr(0x41);
  27.  
  28. my $short_name = 'Test';
  29. my $long_name = 'Test Node 1';
  30. my $report = 'Node is working.';
  31.  
  32. $short_name = $short_name.$filler x ( $pad_len_18 - length( $short_name ) );
  33. $short_name = $short_name.$filler x ( $pad_len_18 - length( $short_name ) );
  34.  
  35. $long_name = $long_name.$filler x ( $pad_len_64 - length( $long_name ) );
  36. $long_name = $long_name.$filler x ( $pad_len_64 - length( $long_name ) );
  37.  
  38. $report = $report.$filler x ( $pad_len_64 - length( $report ) );
  39. $report = $report.$filler x ( $pad_len_64 - length( $report ) );
  40.  
  41. my $numport = chr(0x00).chr(0x08);
  42. my $port_type = chr(0xc0).chr(0xc0).chr(0xc0).chr(0xc0);
  43. my $imput_status = chr(0x80).chr(0x80).chr(0x80).chr(0x80);
  44. my $output_status = chr(0x80).chr(0x80).chr(0x80).chr(0x80);
  45. my $imput_switch = chr(0x10).chr(0x11).chr(0x12).chr(0x13);
  46. my $output_switch = chr(0x00).chr(0x01).chr(0x02).chr(0x03);
  47. my $swvideo = chr(0x00);
  48. my $swmacro = chr(0x55);
  49. my $swremote = chr(0xaa);
  50. my $spare = chr(0x00).chr(0x00).chr(0x00).chr(0x00);
  51. my $MAC = chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00);
  52. #----------------------------------------------------------------------------------
  53.  
  54. #-------ArtPoll-------
  55. my $ArtPoll = $ID.$filler.$space.$filler.$Prover.$ttm.$filler;
  56. #-------ArtPollReply----
  57. my $ArtPollReply = $ID.$filler.'!'.$IP.$Port.$vers.$subsw.$oem.$UBEA.
  58.     $status.$ESTA.$short_name.$long_name.$report.$nump ort.$port_type.$imput_status.$output_status.
  59.     $imput_switch.$output_switch.$swvideo.$swmacro.$sw remote.$spare.$MAC.$filler.$filler;
  60. #-----------------------
  61.  
  62. my $response = IO::Socket::INET->new(
  63.     Proto => "udp",
  64.     PeerPort => "6454",
  65. );
  66.  
  67.  
  68. my $poll = IO::Socket::INET->new(
  69.     PeerAddr=> "2.255.255.255",
  70.     PeerPort => "6454",
  71.     Proto => "udp",
  72.     LocalPort => "6454",
  73. );
  74.  
  75. sub ArtPoll {
  76.     $poll->send($ArtPoll);
  77.     print "ArtPoll sent.\n";
  78. }
  79.  
  80. sub ArtPollReply {
  81.     $response->recv($ArtPollReply,250);
  82. }
  83.  
  84. &ArtPoll;
  85. &ArtPollReply;
  86.  
May 10 '07 #5
KevinADC
4,059 Expert 2GB
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.
May 11 '07 #6
kardon33
158 100+
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.
May 11 '07 #7
KevinADC
4,059 Expert 2GB
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.
May 11 '07 #8
kardon33
158 100+
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.
May 11 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Rad | last post: by
reply views Thread by whetham63 | last post: by
1 post views Thread by Mr. Beck | last post: by
reply views Thread by clemima | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.