Receive Floats using java sockets from C++

前端 未结 1 1372
时光说笑
时光说笑 2021-01-27 14:20

I need to receive an array or a class containing floats from a c++ client to java server using sockets. But the InputStreamReader is not getting it right. Any reasons. Any sugge

相关标签:
1条回答
  • 2021-01-27 14:37

    I suggest you try

    DataInputStream ins = new DataInputStream(socket.getInputStream());
    byte[] bytes = new bytes[48];
    ins.readFuly(bytes);
    ByteBuffer bb = ByteBuffer.wrap(bytes).order(ByteOrder.nativeOrder());
    
    values.tWidth = bb.getFloat();
    value.waterLevel = bb.getFloat();
    // etc
    
    0 讨论(0)
提交回复
热议问题