473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 5704
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

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

Similar topics

0
by: Rad | last post by:
Im trying to lauch a small perl program in cygwin which listens for arguments on a specified port. When executing this line (18) ; my $sock = new IO::Socket::INET(LocalPort => $DAEMONPORT,...
0
by: whetham63 | last post by:
When I run this on my network at home and on my network at work it runs fine. When this is run at a clients network I am receiving a after the first packet is received(There are 2 packets...
1
by: bobano | last post by:
Hi everyone, I am writing a POP3 Client program in Perl. You connect to a POP3 Server and have a running conversation with the mail server using commands from the RFC 1939 Post Office Protocol....
1
by: Mr. Beck | last post by:
Hello, Please Help..... I have been working with some tcp/ip socket communication within a C# program recently. Basicly, I have a program (myProblemProgram) that has a socket connected to...
1
by: kardon33 | last post by:
How would i receive an incoming UDP packet in perl with IO::SOCKET::INET???
1
by: Dimbeswar Pathak | last post by:
I got an error message "use" not allowed in expression at client.pl line 2, at end of line syntax error at client.pl line 2, near "use IO::Socket::INET" Execution of client.pl aborted due to...
0
by: clemima | last post by:
Hi, i have a script that listens on a port for simple text messages and then executes sql to a remote mssql database . The script is started via crontab . There are 2 problems : 1 . The line to...
4
by: pplers | last post by:
use IO::Socket; my $path= "http://website.com/aaa.php"; print q( __________ -/* Script v1.0 *\- ------------------ );
1
by: john2357 | last post by:
I can not use the LWP module, and must use IO::Socket. Using 'Wireshark' and Mozilla and passing in the parameters below I get a valid reply. However Wireshark shows HTTP needs to be 1.1 and that the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.