Need Help Reading Data From Inputstream

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Need Help Reading Data From Inputstream

Postby win1for » Wed Jul 28, 2010 1:18 pm

Hi Guys,

I have a robot and a GUI application running on a GUI. I have a while loop on the robot side that is constantly sending data to the GUI.


Before i send a value, i send first a value which the GUI will use to determine how many consecutive values it must read afterwards for instance i send something like;

Code: Select all
dataout.writeInt(2);
dataout.writeInt(50);
dataout.writeInt(506);
dataout.writeInt(50);
dataout.flush


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

On the GUI side i have i while loop that is in a run() of a thread that is reading from the inputstream continuosly.

Inside the loop on the GUI i have a switch case statement.

Example

Code: Select all
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;

}

}



It is not working as i want. This is what i get:

After it reads the first int, i get a series of numbers that it is reading from the inputstream. i don't know where those numbers come from.

I thought that if it cant read the numbers i send, then it must block, but it isn't.

For the example above this is what i get:

Code: Select all
2
1761635840
1946182912
1845523456
1761636096
1845523200
1006658048
16274152968


All the numbers after the 2, i don't know where they come from. it doesn't read the numbers after the 2 i send.

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


What am i doing wrong? Need help
win1for
Novice
 
Posts: 48
Joined: Tue Mar 02, 2010 11:22 pm

Postby gloomyandy » Wed Jul 28, 2010 4:29 pm

Are you sure this is not just a consequence of you having multiple threads writing to the same OutputStream? Have you fixed that problem yet? You don't by any chance have more than one thread reading an InputStream as well? We probably need to see the actual code that is writing the data to be able to help here...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4114
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Need Help Reading Data From Inputstream

Postby Shawn » Mon Aug 02, 2010 4:37 am

shouldn't you be reading 3 ints in your case 2?

Maybe you should log a default case in your switch to let you know if your indexing is getting messed up!
User avatar
Shawn
Advanced Member
 
Posts: 723
Joined: Wed Sep 12, 2007 4:59 am
Location: Tokyo


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff