Sending character array (as a bytebuffer) via udp

Hi,
I do have to send a udp packet, containing several variables, and the reciever awaits it as a character array ... (C++, cannot change this part!)
As far as I see it, I can only send ByteBuffers via DatagramPackets via udp.
Has anyone a clue how I can convert a ByteBuffer into another Bytebuffer in a way so that the udp reciever gets it as if I had sent a character array instead ?!?
Or is there actually a character array udp sender ?!?
Any help is highly appreciated, big Thanx in advance,
~Carmela

In C++, char' are unsigned bytes. Thus converting between bytes and chars is fairly straight forward. Java treats char as unsigned short (16-bit) so it converts chars to bytes as UTF-8. (By default) Unless you are using special on ascii characters i.e. 128+ all this makes no difference whatsoever.
A bytebuffer is just a container for bytes. You can encode anything as bytes so there is no magic here. Just get the data as bytes and put it into a ByteBuffer.
String string = "text";
ByteBuffer bb = ByteBuffer.wrap(string.getBytes());

Similar Messages

  • Sending character array (as a bytebuffer)

    Hi,
    I do have to send a udp packet, containing several variables, and the reciever aspects it as a character array ... (C++, cannot change this part!)
    As far as I see it, I can only send ByteBuffers via DatagramPackets .
    Has anyone a clue how I can convert a ByteBuffer into another Bytebuffer in a way so that the udp reciever gets it as if I had sent a character array instead ?!?
    Or is there actually a character array udp sender ?!?
    Any help is highly appreciated, big Thanx in advance,
    ~Carmela

    sorry, wrong forum ... please disregard!

  • How does one send a file via UDP?

    I need to send a binary file via UDP. The file has 99 32-bit binary words of data. How do I input the data to the UDP write command? I don't want to send the data sequentially..I would like to send all 99 words in a single UDP transmission. TIA.
    -jlivermore

    Something to be careful of is that while UDP is fast, it is not secure. You can lose packets and there is no way for the sender or receiver to know it was lost. Because UDP doesn't have a "connection" like TCP does, the sender doesn't know if the data is going anywhere and the receivers have no way of knowing if anything is being sent.
    Picture a radio station. A guy working the night shift hopes there is someone somewhere listening to his broadcast, but he doesn't know. Likewise, if you turn on a radio and hear nothing but static, you may be listening to a frequency where there are no stations broadcasting, or the station transmitter might be off the air, or there might be interference keeping you from hearing the signal, but again you don't know which.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Trouble with sending huge arrays via DataSocket​s.

    Hi,
    I am having trouble sending huge arrays via Data Sockets from my main vi on the server PC to the vi on the client PC.
    To further elaborate, in my main vi program I have created 3 arrays called Array1, Array2 and Array3 on my front Panel. By right clicking the mouse on each set of array and from the pop-up menu I selected Data Operations-> DataSocket Connection and I entered dstp://localhost/Array1 and clicked on Publish to broadcast the data from Array1. Similarly, I did the same for Array2 and Array3.
    Now, in my client vi program I have created three arrays on my front Panel to read (Subscribe) the data from the three arrays broadcasted via DataSockets from the server’s main vi program. To subsc
    ribe the data I did the similar process above and clicked on Subscribe to read the data (of course the IP address of the client PC will be different then the server PC so enter the hosts IP address). Once the data is received in the client arrays, I am using LV2 globals so that I can use these arrays on other sub-vi’s locally (instead of having each sub-vi get data from the server directly).
    I succeeded in doing this with two arrays, however when I added the third array the DataSockets would not work consistently. For example the refresh rate would get slower at times and sometimes 2 out of the 3 arrays would update. I don’t know if I have exceeded the limit on how much data DataSockets can broadcast, but I need to have some mechanism to broadcast 6 arrays (approx. 10000 elements for each array) of double digits precision.
    Has anyone come across this issue? Is there another way of broadcasting data more efficiently then DataSockets?
    I would appreciate any
    help that I can get.
    I have attached the files for this program in the zip file.
    First run the Server main program, testServeMainVI.vi, and then the client program, testClientMainVI.vi.
    Thanks
    Nish
    Attachments:
    beta2.zip ‏70 KB

    DataSocket can be a lossy communication. I like the advice to flatten the data to a string, but another option would be to buffer the communcation. The problem might be that the data is being overwritten on the server faster than it is being read. There is an example of buffered datasocket on NI web page: http://venus.ni.com/stage/we/niepd_web_display.DIS​PLAY_EPD4?p_guid=BA3F9DFED17F62C3E034080020E74861&​p_node=DZ52000_US&p_submitted=N&p_rank=&p_answer=&​p_source=Internal
    Also, I have played with the new built in buffered datasocket in LabVIEW 7.0. It is pretty slick. If buffers the data both on the server and the client side.

  • Sending an array of images via web service

    Hi!
    Is it possible to send an array of images using DataHandler[]?
    Thank you!
    Good Day!
    grazieee

    Hi Michael,
    Can I have an example of the JAX-RPC handler method?
    Thank you!!
    Good Day!
    grazieee..
    ================================================================
    "Michael Wooten" <[email protected]> wrote:
    >
    You can return a DataHandler[], but you can't currently pass one to a
    WLS (or WLW)
    web service opertion :-)
    For now, you should consider using a JAX-RPC Handler to achieve the same
    effect.
    Regards,
    Mike Wooten
    "grazieee" <[email protected]> wrote:
    Hi!
    Is it possible to send an array of images using DataHandler[]?
    Thank you!
    Good Day!
    grazieee

  • Transmitting a byte command via UDP

    I hope you'll forgive the newbie question, but my education is in aerospace engineering and not computer science...
    I have a verified specification document which tells me that in order to command a data source to begin transmitting data, I need to send it the following command via UDP:
    1 byte        1 byte               2 bytes                              n bytes
    COMMAND
    01
    00
    Command Code =
    8016
    Data  
    Where the data field is ignored for this command.
    My best understanding of this situation would be to use the Byte Array to String function on an array of U8s which looks like this:
    where the network order is big endian.  However, I have some functioning, inherited code which interfaces with the same data source and issues a start data command using an array which looks like this:
    In classic style, the author of this code has retired and I'm the only other LabVIEW programmer.  I'm not savvy enough to tell whether this array accomplishes the same task and it's my limited understanding of bytes which is causing the confustion or if this command is combined with another command or what.
    Any insight, leading questions, or valuable commentary is appreciated.
    Solved!
    Go to Solution.

    I think I'm starting to understand how bits, bytes, and such behave with LabVIEW.  Kind of confusing without a solid background in computing...
    According to the documentation-when using the startup command--there is no data payload required; it is ignored by the data source.  My only guess for those elements remaining after the 4th element are that they are simply placeholders so that the data source know this is a completed command or that the original programmer copied the array from one of the other commands (which required the data payload) and those are just residual values he knew were ignored and never bothered to delete.  It would be in keeping with the just-get-it-done approach this programmer favored.
    Thanks for the assistance.  I think I can interpret the other commands for this data source now.
    Cheers.

  • Character array type conversion problem

    Hi, I'm using BlazeDS (v3.0.0.544) to remotely call Java code on the server from my Flex client. I'm having trouble when converting a character array type from Java to ActionScript and vice-versa. In my Flex code, if the ActionScript class uses a String type to map to the char[] then the char[] is successfully converted from Java to ActionScript, but not from ActionScript to Java.
    // Extract from ActionScript code
    private var m_charArray:String;
    public function get charArray():String
    return m_charArray;
    public function set charArray(value1:String):void
    m_charArray = value1;
    Alternatively, if my ActionScript class uses an Array type then I can successfully send data from the client and populate a char[] field on the server, but can't send an updated char[] back to my ActionScript class.
    In fact the Flex console reports:
    TypeError: Error #1034: Type Coercion failed: cannot convert "myString" to Array.
    The code this time:
    // Extract from ActionScript code
    private var m_charArray:Array;
    public function get charArray():Array
    return m_charArray;
    public function set charArray(value1:Array):void
    m_charArray = value1;
    All the other types I have tried work successfully, it's only with char arrays that I've hit a problem.
    Any help would be appreciated, thanks.

    Hi Graeme,
    It is how it works. I can see the inconsistency. You can find an example how of echo char[] in blazeds\trunk\qa\apps\qa-regress\testsuites\mxunit\tests\remotingService\dataTypes\CharTy pesTest.mxml. It echos a char[] in return of a string. You can get the char in a string easily string.charAt() and get its length using length(). I think it may be the reason remoting decided to use a string to represent a char[] instead of a generic objects array. It should be more memory efficient. However, I can see that it can turn into problem as what you descibed. When the data has to send back to server, it has to convert back to array. If the char[] type is used inside an object, it is impossible to do the conversion unless the getter and setter are generic
    public function get charArray():Object
    return m_charArray;
    public function set charArray(value1:Object):void
    if (value1 is String)
    m_charArray = new Array();
    //copy the string elements to it
    else
    m_charArray = value1;
    I know it is ugly, but it the only work around I can think of. I think it needs to log a bug to correct this conversion behavior
    William

  • Another question?? being able to send byte arrays containing multiple types

    Hi,
    I have a question which I would really appreciate any help on.
    I am trying to send a byte array, that contains multiple types using a UDP app. and then receive it on the other end.
    So far I have been able to do this using the following code. Please note that I create a new String, Float or Double object to be able to correctly send and receive. Here is the code:
    //this is on the client side...
    String mymessage ="Here is your stuff from your client" ;
    int nbr = 22; Double nbr2 = new Double(1232.11223);
    Float nbr3 = new Float(8098098.809808);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(mymessage);
    oos.writeInt(nbr);
    oos.writeObject(nbr2);
    oos.writeObject(nbr3);
    oos.close();
    byte[] buffer = baos.toByteArray();
    socket.send(packet);
    //this is on the server side...
    byte [] buffer = new byte [5000];
    String mymessage = null; int nbr = 0; Double nbr2 = null;
    Float nbr3 = null;
    mymessage = (String)ois.readObject();
    nbr = ois.readInt();
    nbr2 = (Double) ois.readObject();
    nbr3 = (Float) ois.readObject();
    My main question here is that I have to create a new Float and Double object to be able to send and receive this byte array correctly. However, I would like to be able to have to only create 1object, stuff it with the String, int, Float and Double, send it and then correctly receive it on the other end.
    So I tried creating another class, and then creating an obj of this class and stuffing it with the 4 types:
    public class O_struct{ 
    //the indiv. objects to be sent...
    public String mymessage; public int nbr; public Double nbr2;
    public Float nbr3;
    //construct...
    public O_struct(String mymessage_c, int nbr_c, double nbr2_c, float nbr3_c){
    my_message = my_message_c;
    nbr = nbr_c;
    nbr2 = new Double(nbr2_c);
    nbr3 = new Float(nbr3_c);
    Then in main, using this new class:
    in main():
    O_struct some_obj_client = new O_struct("Here is your stuff from your client", 22, 1232.1234, 890980980.798);
    oos.writeObject(some_obj_client);
    oos.close();
    send code....according to UDP
    However on the receiving side, I am not sure how to be able to correctly retrieve the 4 types. Before I was explicitely creating those objects for sending, then I was casting them again on the receiving side to retrieve then and it does work.
    But if I create a O_struct object and cast it as I did before with the indiv objects on the receiving end, I can't get the correct retrievals.
    My code, on the server side:
    O_struct some_obj_server = new O_struct(null, null, null. null);
    some_obj_server = (O_struct)ois.readObject();
    My main goal is to be able to send 4 types in a byte array, but the way I have written this code, I have to create a Float and Double obj to be able to send and receive correctly. I would rather not have to directly create these objects, but rather just create one object and be able to send and receive the information on both ends
    I might be making this more complicated than needed, but this was the only way I could figure out how to do this and any help will be greatly appreciated.
    If there an easier way to do I certainly will appreciate that advise as well.
    Thanks.

    which forum should I be posting this on?Serialization.
    To get you started...
    public class O_struct implements Serializable {                                                                                                                                                                                                                                                                                   

  • I have an iPad 2, and I am sending PDF file to my iPad, via a Hotmail email. But, the PDF arrives to the iPad in Mail already opended, as a picture on the bottom of the email. Is there a way to prevent it from auto open, so I can open with iBooks instead?

    I have an iPad 2, and I am sending PDF files to my iPad, via a Hotmail account. But, the PDF arrives to the iPad Mail account already opened at the bottom of the email. Is there a way to prevent this auto-opening of the PDF. I've seen screen shots with the box, and PDF listed inside the box, but mine open automatically. I want to get them into iBooks...?

    I am having the same problem and it is even bigger.
    When opening a 1-page PDF in iBooks and sending it via mail it is sent inline as preview, but the recipient cannot open the file anymore. Also on iPad and iPhone there is no "open in" possible.
    Somehow the mail app does destroy the file. What is going wrong?

  • How to send a copy of a document via Gmail?

    Hello,
    After the update to iOS 8.1, I can see the option to send a copy of the document via email. In my case I was able to send the document via Yahoo mail app installed on the device. However, I cannot send through the GMail app installed. I am not using the Apple Email application in this case.
    Could someone help me?

    I have found that the best way to send websites or set them up is to do it in an organized way.
    When you're in Dreamweaver, you set up a site as a folder on your local hard drive and everything should be stored there.
    Windows and Macs both have "user" areas and your "user" would be you. If you created a user file with your Adobe handle, it would be "iwontbuythis."
    So, within "iwontbuythis" you have folders, such as "Documents" and "photos" and so on. In my user area, which is "Mark," I created another folder called "Sites." That's where my websites I create in Dreamweaver go and I have an "alias" or "shortcut" on my desktop to that.
    Whenever I create a new website, it's in a folder underneath "Sites." So my website for my company, Hollis Internet Marketing, LLC, is in a folder under "Sites" called "HIM."
    If I need to send that website to anyone, I simply zip up my "HIM" folder and send everything within it. If it's too big for an email, I use Dropbox, or I place it on my server for download.

  • Using values to create a scatter plot in a character array

    Ok, I am fairly new to the language and i am working ona program that will first, get the users input of how many values and the x and y of each value, it will store it into a 2d array and also have the x-squared value and X*Y value. I have all the entry of the data working and the calculation for the line of best fit works correctly.
    What i need help with is, I want to take those values and store them into a character array that will display the points where they belong with a '*'. I also need to make the graph lines on the left and bottom. If the values are less than 10 for the x or y, i need to make them 10. The Y line needs to be rounded to the next highest 10s place if its over 10. I have tried a few things and i realised that it is completly wrong..
    public void graph(int[][] grid, int n)
                int highY = 0;
                for(int x=0;x<n; x++)
                 if (grid[x][1] > highY)
                    highY = grid[x][1];
             char[][] output = new char[n+1][highY+1];
             for(int z=0; z<highY+1; z++)
                 output[z][0]='+';
             for(int w=0; w<n+1; w++)
                 output[n][w]='+';
             int tempx=1; int tempy=1;
             output[tempx][tempy]='*';
             while(tempx<n+1)
                 tempy++;
                 if(tempy==highY+1)
                     tempx++;
                     tempy=0;
                 output[tempx][tempy]='*';
             System.out.println();
               for (int I=0; I<n+1; I++)
                      for (int J=0; J<highY+1; J++)
                          System.out.print(output[I][J]);
                          System.out.println();
    }Grid is the grid of the values, and for the [x][1] is all the Y values going down, [x][0] is the X values. the x would go up to however many values there are. Again, i know the code above is wrong.
    Any thoughts or suggestions would be appreciated. Also, if you need any more info from what i have done please ask.

    Big El,
    I think you can ditch the RGB To Color block, if that's what you're using.
    If I understand your description, what you need to do is use Interleave 1D Arrays to combine your three sine arrays together into one long array. Then use Draw Flattened Pixmap to turn the array into a picture. You can use Bundle By Name to stick your interleaved array into the image data cluster, and also make sure to specify 24-bit image depth and an appropriate bounding box.
    Hope that makes sense,
    John

  • Converting bytes to character array problem

    I am trying to convert a byte array into a character array, however no matter which Character Set i choose i am always getting the '?' character for some of the bytes which means that it was unable to convert the byte to a character.
    What i want is very simple. i.e. map the byte array to its Extended ASCII format which actually is no change in the bit represtation of the actual byte. But i cannot seem to do this in java.
    Does anyone have any idea how to get around this problem?

    Thanks for responding.
    I have however arrived at a solution. A little un-elegant but it seems to do the job.
    I am converting each byte into char manually by this algorithm:
              for (int i=0;i<compressedDataLength;i++)
                   if (((int) output)<0)
                        k=(127-((int) output[i]));
                        outputChr[i]=((char) k);
                   else
                        k=((int) output[i]);
                        outputChr[i]=((char) k);
                   System.out.println(k);
    where output is the byte array and outputChr is the character array

  • Send spool id output (sap script) via email in PDF format

    Dear friends,
    Looking for sample program to send spool id output of sapscript via email in PDF format.
    Regards,
    Praveen Lobo

    Hi,
    Try this code..
    * Parameters.
    PARAMETERS: p_email(50) LOWER CASE.
    PARAMETERS: p_spool LIKE tsp01-rqident.
    * Data declarations.
    DATA: plist LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
    DATA: document_data LIKE sodocchgi1.
    DATA: so_ali LIKE soli OCCURS 100 WITH HEADER LINE.
    DATA: real_type LIKE soodk-objtp.
    DATA: sp_lang LIKE tst01-dlang.
    DATA: line_size TYPE i VALUE 255.
    DATA: v_name LIKE soextreci1-receiver.
    DATA rec_tab LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
    * Get the spool data.
    CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
    EXPORTING
    rqident = p_spool
    first_line = 1
    last_line = 0
    desired_type = ' '
    IMPORTING
    real_type = real_type
    sp_lang = sp_lang
    TABLES
    buffer = so_ali
    EXCEPTIONS
    no_such_job = 1
    job_contains_no_data = 2
    selection_empty = 3
    no_permission = 4
    can_not_access = 5
    read_error = 6
    type_no_match = 7
    OTHERS = 8.
    * Check the return code.
    IF sy-subrc <> 0.
    MESSAGE s208(00) WITH 'Error'.
    LEAVE LIST-PROCESSING.
    ENDIF.
    * Prepare the data.
    plist-transf_bin = 'X'.
    plist-head_start = 0.
    plist-head_num = 0.
    plist-body_start = 0.
    plist-body_num = 0.
    plist-doc_type = 'RAW'.
    plist-obj_descr = 'Spool data'.
    APPEND plist.
    plist-transf_bin = 'X'.
    plist-head_start = 0.
    plist-head_num = 0.
    plist-body_start = 1.
    DESCRIBE TABLE so_ali LINES plist-body_num.
    plist-doc_type = real_type.
    * Get the size.
    READ TABLE so_ali INDEX plist-body_num.
    plist-doc_size = ( plist-body_num - 1 ) * line_size
    + STRLEN( so_ali ).
    APPEND plist.
    * Move the receiver address.
    MOVE: p_email TO rec_tab-receiver,
    'U' TO rec_tab-rec_type.
    APPEND rec_tab.
    IF NOT sp_lang IS INITIAL.
    document_data-obj_langu = sp_lang.
    ELSE.
    document_data-obj_langu = sy-langu.
    ENDIF.
    v_name = sy-uname.
    * Subject.
    document_data-obj_descr = 'Spool attached'.
    * Send the email.
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
    document_data = document_data
    sender_address = v_name
    sender_address_type = 'B'
    TABLES
    packing_list = plist
    contents_bin = so_ali
    receivers = rec_tab
    EXCEPTIONS
    too_many_receivers = 1
    document_not_sent = 2
    document_type_not_exist = 3
    operation_no_authorization = 4
    parameter_error = 5
    x_error = 6
    enqueue_error = 7
    OTHERS = 8.
    IF sy-subrc <> 0.
    MESSAGE e208(00) WITH 'Error in sending email'.
    ENDIF.
    COMMIT WORK.
    * Send the email immediately.
    SUBMIT rsconn01
    WITH mode = 'INT'
    AND RETURN.
    * Success message.
    MESSAGE s208(00) WITH 'Email sent'.
    Thanks
    Naren

  • Send an array to php

    I have to send a large number of variable to php and want to
    avoid having to repeatedly call the php script, so I thought the
    way to do this would be to send an array. I generally use code
    similar to the following to receive individual variables in php:
    $count = mysql_real_escape_string($_GET["count"]);
    Unfortunately, I don't know how to accept an array from Flex
    into PHP. I realize that this is more of a php question than a Flex
    question, but am hoping that someone has done this before. Here's
    how I want to send the array from Flex:

    These links might help:
    link1
    link2
    link3

  • How do I scan a photo to a file and then send the file as an attachment via email.

    How do I scan a photo to a file and then send the file as an attachment  via email.

    All of this depends largely on what printer /software you have, which Email client you use and to some extent which OS you are running.
    Most HP printers have HP Solution Center which is used to set up scanning,choosing where to save,etc. Once a file/photo is scanned and saved to the folder, open the folder.Select the file and at the top of the window should be the option to 'Email'.
    ******Clicking the Thumbs-Up button is a way to say -Thanks!.******
    **Click Accept as Solution on a Reply that solves your issue to help others**

Maybe you are looking for