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:
Code :
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:
Code :
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...
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??
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...