1
int port = 18000;
DatagramSocket serverSocket = new DatagramSocket(port);
byte[] receiveData = new byte[8];

System.out.println("Server Listing on Port: "+port);
String x;

while (true){
  DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
  serverSocket.receive(receivePacket);

?? Double x = new Doulbe.parseBytes(recievedPacket)

4

4 に答える 4

2

あなたが使うことができますByteBuffer

Double x = ByteBuffer.wrap(receiveData).getDouble();
于 2012-12-28T14:38:18.493 に答える
1

使用するjava.nio.ByteBuffer

何かのようなもの:

private static ByteBuffer buffer = ByteBuffer.allocate(8);    

public static byte[] encodeDouble(double x) {
    buffer.clear();
    buffer.putDouble(0, x);
    return buffer.array();
}

public static double decodeDouble(byte[] bytes) {
    buffer.clear();
    buffer.put(bytes);
    buffer.flip(); 
    return buffer.getDouble();
}    
于 2012-12-28T14:40:16.140 に答える
1
ByteBuffer.wrap(receiveData.getData()).getDouble();
于 2012-12-28T14:40:18.360 に答える
0
java.io.DataInputStream.readDouble()
于 2012-12-28T15:04:04.520 に答える