473,399 Members | 3,401 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,399 software developers and data experts.

Pack and unpack

158 100+
Ok what i am trying to do with my script i send a poll and receive a reply and read that reply. I have the Poll work properly but what i need help with is trying to convert the reply from ascii to regular text.

My reply consist of 30 different variables and i need them to be separated. my code so far is.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. print "Content-type:text/html\n\n";
  4. use IO::Socket;
  5.  
  6. #Poll
  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 $ID = $header.$filler;
  13.  
  14. my $ArtPoll = $ID.$filler.$space.$filler.$Prover.$ttm.$filler;
  15.  
  16.  
  17. #My Reply.
  18. my $T_ArtPollReply = pack("A8 S C C C C C C C C C S C18 C64 C64 C C C C C C C C C C C C C C C6 C32",
  19.     $ID,
  20.     $OpCode,
  21.     $BoxAddr,
  22.     $VersionInfoH,
  23.     $VersionInfo,
  24.     $SubSwitchH,
  25.     $SubSwitch,
  26.     $OemH,
  27.     $Oem,
  28.     $UbeaVersion,
  29.     $Status,
  30.     $EstaMan,
  31.     $ShortName,
  32.     $LongName,
  33.     $NodeReport,
  34.     $NumPortsH,
  35.     $NumPorts,
  36.     $PortTypes,
  37.     $GoodInput,
  38.     $GoodOutput,
  39.     $Swin,
  40.     $Swout,
  41.     $SwVideo,
  42.     $SwMacro,
  43.     $SwRemote,
  44.     $Spare1,
  45.     $Spare2,
  46.     $Spare3,
  47.     $Style,
  48.     $Mac,
  49.     $Filler,
  50. );
  51.  
  52. $Node_Ip = '2.0.0.1';
  53.  
  54. my $poll = IO::Socket::INET->new(
  55.     PeerAddr    => $Node_Ip,
  56.     PeerPort    => "6454",
  57.     Proto        => "udp",
  58.     LocalPort    => "6454",
  59. );
  60.  
  61. sub ArtPoll {
  62.     $poll->send($ArtPoll);
  63.     print "ArtPoll sent.\n<hr>";
  64.  
  65.     sub Reply {
  66.         $poll->recv($T_ArtPollReply,250);
  67.         print $T_ArtPollReply;
  68.     }
  69.     &Reply;
  70. }
  71.  
  72. &ArtPoll;
  73.  
When i run it i try to print the reply but i get[HTML]<br>[/HTML] Art-Net??!??6???̉LATest1?????????????Test Node ?????????????????????????????????????????????????? ????#0001 [0019] Power On Tests Pass?????????????????????????????????€€??????€€?? ??????????????¦?

i know i have to do something with unpack or something but not sure if some one could help me out it would be very helpful.
Jun 13 '07 #1
0 1408

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

Similar topics

1
by: Johannes | last post by:
Hi, I tried to pack eight integer values and one string into one binary string, which I would like to store in a mysql db. I encountered two problems doing this: 1) $this->packed =...
2
by: Sergey Dorofeev | last post by:
I can use string.unpack if string in struct uses fixed amount of bytes. But is there some extension to struct modue, which allows to unpack zero-terminated string, size of which is unknown? E.g....
4
by: Stacy Mader | last post by:
Greetings all, I have a VMS binary file with weather data. The record on each line is 1xint(8) 12xint(2) Using the perl unpack function, I can decode the binary file like this: <snip>
18
by: p.lavarre | last post by:
Can Python not express the idea of a three-byte int? For instance, in the working example below, can we somehow collapse the three calls of struct.pack into one? 08 12 34 56 80 00 I ask...
0
by: Steve | last post by:
Are there any gurus of the pack/unpack world out there that can help me with this one? I have an encrypted string which I'm reading from a zipped file. It was written using pack ( "la" ....
5
by: andmarti | last post by:
If I build a strict with: import struct print struck.pack ('i', 1) it returns a '\n'. What's wrong with it??? :( --
1
by: praveen0437 | last post by:
hi i know about format argument in pack and unpack like b h i etc but in some cases i am getting < or = symbols along with them what does they signifies for example struct.pack( "<cI", 'n',...
5
by: tmp123 | last post by:
Hello, Thanks for your time. After review the "struct" documentation, it seems there are no option to pack/unpack zero terminated strings. By example, if the packed data contains: byte +...
1
by: joe shoemaker | last post by:
If you have the following: data = unpack('>L', sock.recv(4)) Does this line of code means that incoming data is big endian and unpack it to endianess of local machine? If local machine is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.