java - Need Help Reading Data From Inputstream -


I have a robot and a GUI application is running on the GUI. Sending data to GUI.

Before I send a value, I first send a value that the GUI will use to determine the constant values, for example afterwards I send something like this;

  dataout.writing (2); Dataout.writeInt (50); Dataout.writeInt (506); Dataout.writeInt (50); Dataout.flush  

here reads GUI 2 and then under 2, it will read the next two integers.

The GUI has come to me on the side while the loop is one thread which is constantly reading from the inputstream.

I have a switch case statement inside the loop at the GUI.

Example

  while (true) {int val = dataIn.readIn () switch (val) {case 1: int color = readInt (); break; Case 2: int me = readInt (); Int You = readInt (); break; Case 3: int megg = readInt (); Int youss = readInt (); Int mes = readInt (); Int youe = readInt (); break; }}  

T is not working as I want, this is what I get:

After this I have read the intro for the first time, Series which is reading it from the inputstream. I do not know where these numbers come from.

I thought that if the number that I send does not read, then it has to be blocked, but it is not.

Compared to the above, I get this:

  2 1761635840 1946182912 1845523456 1761636096 1845523200 1006658048 16274152968 All numbers after 2, I do not know they are here Come on. After sending this number 2, I do not read.  

I tried to insert some threads sleep (1000) but it is not working.

What am I doing wrong? Need help

CODE

  // Robot executes this code for the public class Folksar collar sensor reader Runnable {DataOutputStream outputStream; Color sensor color sensor; Public forkliftcrollersrider (color sensor color sensor, data output stream output stream) {this.outputstream = outputstream; This.colorSensor = Color sensor; } Run Public Zero () {int code = 1; While (code == 1) {try {thread.sleep (1000); OutputStream.writeInt (10); OutputStream.flush (); OutputStream.writeInt (2); OutputStream.flush (); } Hold (exception e) {}} try {thread.leep (1000); OutputStream.writeInt (20); OutputStream.flush (); OutputStream.writeInt (4); OutputStream.flush (); } Hold (exception e) {}}}} // This code gets on the GUI public class runanble {int num = this.dataIn.readInt (); Public Zero Run () {Switch (num) {Case 10: int color = this.dataIn.read (); break; Case 20: int c = this.dataIn.read (); break; Default; }}} // I am using NXTConnector from GUI to create robot connections. // I read the data again to use DataTouchStream  

Whether the text Intentions & lt; B mean anything to you? You are reading from your input stream; This is the number that corresponds to a certain character set. My guess is that you have to write a little HTML in your output stream. Are you sure you are just writing data over the stream and not even the built-in output stream at the same time? Also, does the code you read actually appear? If so, how is the readInt () method defined?

Edit : Snippet to work above.

  int input = 184549376; Byte [] bytes = {(byte) (input> 24), (byte) (input> gt;> 16), (byte) (input> gt; 8), (byte) )}; System.out.printf ("int:% d hex:% 08X string:% s", input, input, new string (bytes));   

Edit # 2 : In your code, you type with writeInt () and read () It is exactly the kind of non-homogeneity I was talking about. Use should readInt () to read the field written from writeInt () . , Which you are using, reads a byte of data and stores it in an int that you do not want.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -