Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: 1 packet delay with inputstream

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation 1 packet delay with inputstream

    I'm writing some code to receive an Inputstream from a node. for this I use a ProcessBuilder which starts up my coap-client to be able to receive the packets.
    I buffer all my input. check code below:
     
    		command = path + "./coap-client -m GET -p 61616 coap://[aaaa::c30c:0:0:379]/notifications -s 90";
     
    			try {
    				synchronized(command) {
    			        final ProcessBuilder pb = new ProcessBuilder("bash", "-c", command);
    			        // merge child's error and normal output streams.
    			        // Note it is not called setRedirectErrorStream.
    			        pb.redirectErrorStream( true );
     
    			        	//p = Runtime.getRuntime().exec(command);
    			        p = pb.start();
    						System.out.println("process started");
     
    					}
     
    InputStream is = p.getInputStream();
     
    new Thread( new Receiver( is ) ).start();
    				try
    	            {
    					p.waitFor();
    	            }
    				catch ( InterruptedException e )
    	            {
    					Thread.currentThread().interrupt();
    	            }
     
    } catch (IOException e) {
    							// TODO Auto-generated catch block
    							e.printStackTrace();
    						}  finally {}
    					}
    This is my main code. The code that reads out the buffer is listed below:
    public void run()
    	        {
    	    		String line;
    	            final BufferedReader br = new BufferedReader( new InputStreamReader( is ), 100); /* keep small for testing */
    					line = br.readLine();
    				System.out.println(line);
     
    	            try {
    	            	while ( ( line = br.readLine() ) != null )
    	                {
    	            		System.out.println( line );
     
    	            		line = br.readLine();
    	                }
    	            br.close();
    	            } catch (IOException e) {
    	                e.printStackTrace();
    	            }
    	       }

    The packages I receive in my buffer are JSON formatted packets. I'm able to display those packets on the eclipse console but they appear with a 1 packet delay.
    When I start my program I should immediately get the acknowledge package from the node. But the problem is that I only get my Ack-packet when a new notification has arrived in the buffer... I've looked for delays in the readLine() function but I haven't found any solution yet.

    please help me out here...


  2. #2
    Member
    Join Date
    Jun 2011
    Location
    Rhode Island
    Posts
    69
    My Mood
    Bored
    Thanks
    11
    Thanked 7 Times in 6 Posts

    Default Re: 1 packet delay with inputstream

    just possible it may help, do a buffer flush. I assume your delay comes when the buffer is flushed out from the I/O stream. Question are you getting all your data you need its just a delay??

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 1 packet delay with inputstream

    Yes I get all my data but always with a 1 packet delay... so at the start I should get the ACK from my node, but at the moment in my java I get nothing. I tried to debug it and I noticed that my buffer in java was still empty. Only when the second package, a notification is sent from the node, I receive my ACK in my java buffer, and I assume my notification is stuck in the coap-client(written in C) I/O Stream buffer...

Similar Threads

  1. Looping an inputstream
    By Trunk Monkeey in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 25th, 2011, 03:39 PM
  2. [SOLVED] InputStream to File
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: May 2nd, 2011, 02:05 PM
  3. Delay.
    By Tjstretch in forum Java Theory & Questions
    Replies: 1
    Last Post: October 21st, 2010, 12:18 PM
  4. Delay/Wait/Pause in Java + AirBrushing
    By obliza in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 27th, 2009, 11:27 AM
  5. Replies: 6
    Last Post: October 23rd, 2009, 04:53 AM