Need Help Reading Data From Inputstream

Post your NXJ projects, project ideas, etc here!

Moderators: imaqine, 99jonathan, roger

Posts: 48
Joined: Tue Mar 02, 2010 11:22 pm

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


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.


Code: Select all

int val = dataIn.readIn()


    case 1:
            int color = readInt();

case 2:
         int me= readInt();
         int you= readInt();

case 3:
         int megg = readInt();
         int youss = readInt();
          int mes = readInt();
         int youe = readInt();



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


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

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

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...


User avatar
Advanced Member
Posts: 723
Joined: Wed Sep 12, 2007 4:59 am
Location: Tokyo

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!

Return to “NXJ Projects”

Who is online

Users browsing this forum: No registered users and 4 guests