0 votes
asked by (18 points)
Please, what is wrong with this Java program trying to get a Dataref using XPlane 11 UDP protocol?

I indeed receive the replied message, but the code = 99 (this should be the identifier for the Dataref I requested) does not come with it. It comes with some garbage instead.

Thanks for any additional information about this.





So this one is cool: Send in the 5 chars RREF (null-terminated!) plus this struct:


struct dref_struct_in


    xint dref_freq        ;

    xint dref_en        ;

    xchr dref_string[400]    ;




Where dref_en is the integer code you want X-Plane to send back with the dataref value so you can tell WHICH dataref X-Plane is giving you! (since you are likely to ask for MANY different datarefs!)

Where dref_string is the dataref string that you want X-Plane to send to you!


And, if the dataref is to an ARRAY of values (like engine thrust, since there can be 8 engines), just add [xxx] to the end, where “xxx” is the array index you want X-Plane to send!

The [ and ] should simply surround the number to indicate that the number is the index you want.

So, send in “sim/flightmodel/engine/POINT_thrust[1] “to have X-Plane send the second engine, for example (since we start at 0!)


X-Plane will send the message right back to the IP address and port number you sent the RREF command from.

You will get:


struct dref_struct_out


    xint dref_en    ;

    xflt dref_flt    ;



Where dref_en is the integer code you sent in for this dataref in the struct above.

Where dref_flt is the dataref value, in machine-native floating-point value, even for ints!


So, of course, you can send in all the RREF messages you want, to get all the dataref values back that you want!



Send in a “dref_freq” of 0 to stop having X-Pane send the dataref values."



However when I receive the replied message, the field "xint dref_en" does not bring the identifier I provided when I asked for the Dataref information.


Please, see my Java source code below:


import java.io.*;

import java.net.*;

import java.nio.*;

import java.util.*;


public class Dataref {


    private static final int LENGTH = 414;


       public static void main(String args[]) throws Exception {


        DatagramSocket clientSocket = new DatagramSocket();

        InetAddress IPAddress = InetAddress.getByName("localhost");

        byte[] sendData = new byte[LENGTH];

        byte[] receiveData = new byte[13];




        ByteBuffer buffer = ByteBuffer.allocate(LENGTH);

        buffer = buffer.order(ByteOrder.LITTLE_ENDIAN);

        String cmd = new String("RREF");

        //String msg = new String("sim/cockpit2/annunciators/stall_warning[0]");

        String msg = new String("sim/flightmodel/engine/POINT_thrust[0]");

        int freq = 1;

        int code = 99;

        byte zero = 0;

        buffer = buffer.put(cmd.getBytes());

        buffer = buffer.put(zero);

        buffer = buffer.order(ByteOrder.LITTLE_ENDIAN).putInt(freq);

        buffer = buffer.order(ByteOrder.LITTLE_ENDIAN).putInt(code);

        buffer = buffer.put(msg.getBytes());

        for (int i = cmd.length() + msg.length() + 9; i < LENGTH; i++) {

            buffer = buffer.put(zero);


        sendData = buffer.array();


        for (int i = 0; i < sendData.length; i++) {

            System.out.print(sendData[i]+" ");




        DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 49000);



        //while (true) {



              //DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length, IPAddress, 49001);

              DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);



              String modifiedSentence = new String(receivePacket.getData());

              System.out.println("Message Received: " + modifiedSentence);


            for (int i = 0; i < receivePacket.getData().length; i++) {

                System.out.print(receivePacket.getData()[i]+" ");




              ByteBuffer bt = ByteBuffer.wrap(receivePacket.getData());

              int id = bt.order(ByteOrder.LITTLE_ENDIAN).getInt(5);

              float value = bt.order(ByteOrder.LITTLE_ENDIAN).getFloat(9);

              System.out.println("Id: "+id+" Value: "+value);






1 Answer

+1 vote
answered by (19.3k points)

UDP and plugin development support is a bit beyond the scope of this forum. If you would like additional help, I would recommend checking out the X-Plane.org forum (not affiliated with Laminar Research).

Welcome to X-Plane Q&A, where you can ask support questions and get answers from members of the community.

This site is for X-Plane support questions only. Please search for existing answers before posting your question. Off-topic questions will be locked.

If you’re new, you’ll need to register before asking your first question.

If your question is answered, click on the check mark to select the best response.