2

I need to read the double speed value of a driving simulator over tcp/ip.

I tried it like this:

Socket s = new Socket(server, port);
InputStream is = s.getInputStream();
DataInputStream dis = new DataInputStream(is);
System.out.println(dis.readDouble());

With BigEndian = true in the configuration of the simulator I get values like this which make no sense:

-1.565600306167059E-119
 2.6794374850840603E-248
-2.8742899426422626E-168
-1.858946187722445E-277
 1.0067114608326767E54
-0.001054984626127145
-3.862596704088319E-110
 4.618147910668653E-193
-9.491033037580185E290

With BigEndian = false the first output is the correct value followed by 7 nonsense values and so on like this:

109.94424404374932
1.0152777137342873E132
3.810036543451522E-70
5.888865755856121E100
-3.430929070370842E67
1.0937105040100144E-105
-1.809009002903045E-259
2.7053994656972186E-23
105.04537620848295
1.304469700127963E126
-1.3728712552450811E284
...

This is what wireshark shows for 1 packet:

wireshark output

Does anyone have an idea how to get only the correct values?

l'L'l
  • 44,951
  • 10
  • 95
  • 146
klipper
  • 21
  • 3
  • Do you know how the data is encoded? Is there a specification? If not, how do you know they're doubles? – David Schwartz Dec 05 '18 at 07:16
  • I dont know how the data is encoded. This is the SendDefinition where i can set double as Datatype: = (( , [, , , ])); – klipper Dec 05 '18 at 07:22
  • TCP is byte-oriented, so you need to make sure that the whole double has been received by the socket before decoding it. Assuming double is 8 byte, check that the socket has more than 8 bytes before calling readDouble. (C programmer) – FormerNcp Dec 05 '18 at 08:02
  • Your definition suggests there should be a variable name and a data type, but I can't see a name there. Your reader should be attempting to read a name, then a type you need to decode followed by the data. – Peter Lawrey Dec 05 '18 at 09:11
  • @FormerNcp `readDouble()` already does exactly that. – user207421 Dec 05 '18 at 09:36

0 Answers0