in reply to Send a UDP Packet with bunch of numbers in PERL?

Can you describe what problem you are experiencing when you run your code ?

The immediate issue I see is that $DATA_to_be_SENT is not initialized.

Why can't you simply set $DATA_to_be_SENT=$_ ?

Your problem description is not clear enough. Does "packet of Numeric values" mean binary, fixed size, decimal, or comma separated ? IS the packet fixed size ?

You may need to do a "chomp" after you read the data, unless you want/need to send the "\n" to the remote end.

Always "use strict;", particularly if you are a beginner.

        "Software interprets lawyers as damage, and routes around them" - Larry Wall

  • Comment on Re: Send a UDP Packet with bunch of numbers in PERL?

Replies are listed 'Best First'.
Re^2: Send a UDP Packet with bunch of numbers in PERL?
by AryanSinha (Initiate) on Aug 18, 2016 at 19:14 UTC
    This is just a piece of code to explain at a high level. So,

    1) I can't just send the data in string and cannot assign it the $DATA_to_be_SENT = $_ ; as $_ returns a string which in my case would be "-2.3,-4.5,901,223,34.098"

    2) My Receiving end is a hardware which can only work on Floating numbers and all these five numbers should be sent within ONE Packet in the same order.

    3) I noticed that I can do something like this for hexadecimal numbers

    $socket->send("\x-2.3,\x-4.5,\x901,\x223,\x34.098");
    If I try to use "\d-2.3,\d-4.5,\d901,\d223,\d34.098" and observe the network in wireshark , I am seeing the letter d along with the values.

    So I believe you got a better insight of what i am trying to ask.

      Does your hardware accept a number as a string, or does it desire the floating-point encoding of the number? (Yes, this is re-asking what NetWallah already asked, but maybe in a slightly more prominent way, with some extra clarifications following below.)

      • if it wants a string, does it want it the numbers to each be a certain number of characters, or is there a specific delimiter between them (your examples imply a comma)
      • if it wants floating-point encoding of the number, does it want single (32bit), double (64bit), long double (128bit) or something else? what endian-ness? Once you know the exact format of the number it desires, you can split your string on the commas (or use a prebuilt CSV module) to get a list of the floating-point values, then use pack to encode the floating points into the underlying representation that your hardware understands: your format will be one of f (single), d (double), or D (long double); with perl ≥ v5.10, you can add a modifier, > for big-endian or < for little-endian.

      Once you have the answers to those, try coding it up. If you still need help afterwards, show us the coding progress you've made, and what's still not behaving as you expect.

        * My Hardware only accepts floating point encoding of the number.

        * It has to be either single (or) double . It has Big-Endian format .

        * I did split the string to an array of my floating point values.

        Do you mean to say that i need to use pack module so that it is transmitted viably as per floating point values . ???

        I will try to code now and post the answers.. Thanks
        Hello , I have a quick question in reagard to the numbers while UDP packet is created. I have used pack function to embed a value according to a float (f) expression. Do I need to do that to all numbers individually and Even if by doing so , How can i Send the packet with five different numbers at once. ?>