I have a java program written that simply receives data sent through a UDP socket and prints it to the screen. The data that is received is sent from another computer that uses matlab to send the data. I am pretty sure that the matlab simulation is fine because all it does is take a constant value of 2 with a double data type, uses a byte packer to pack the data and sends it through a UDP block to the specified IP Address and port. I concurrently run the java code on another pc which receives the data packet as a byte array of length 1024.
The data is received just fine, however the value that is constantly printed is
4.7783097267364807 E -299.
I am not sure if my code is grabbing the desired data from the packet correctly or if the ByteBuffer.wrap(.....).getDouble() function is used correctly. Any help would be greatly appreciated
import java.io.*;
import java.net.*;
import java.nio.ByteBuffer;
class receiver
{
public static void main(String args[]) throws Exception
{
DatagramSocket serverSocket = new DatagramSocket(1024);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
System.out.println("Listening...");
while(true)
{
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
double data = ByteBuffer.wrap(receiveData).getDouble();
System.out.println(data);
}
}
}