|
import java.io.IOException;
|
|
|
|
import net.named_data.jndn.*;
|
|
import net.named_data.jndn.encoding.EncodingException;
|
|
|
|
public class JNDNTest {
|
|
public static void main(String[] args) {
|
|
NDNResponder r = new NDNResponder();
|
|
|
|
Face face = new Face("localhost");
|
|
(new Thread(new NDNProcessEvents(face))).start();
|
|
|
|
try {
|
|
face.expressInterest(new Interest(new Name("/foo/bar/baz")), r, r);
|
|
//face.expressInterest(new Interest(new Name("/foo/bar/baz"), 1000), r, r);
|
|
} catch (IOException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static class NDNResponder implements OnData, OnTimeout {
|
|
@Override
|
|
public void onTimeout(Interest interest) {
|
|
System.out.println("Timeout: " + interest.getName().toUri());
|
|
System.exit(1);
|
|
}
|
|
|
|
@Override
|
|
public void onData(Interest interest, Data data) {
|
|
System.out.println("Huh, got back data...");
|
|
System.exit(0);
|
|
}
|
|
}
|
|
|
|
public static class NDNProcessEvents implements Runnable {
|
|
private Face face = null;
|
|
|
|
public NDNProcessEvents(Face f) {
|
|
this.face = f;
|
|
}
|
|
|
|
// Run the NDN event loop to process incoming Interests and Data
|
|
public void run() {
|
|
while (true) {
|
|
try {
|
|
this.face.processEvents();
|
|
|
|
Thread.sleep(50);
|
|
} catch (IOException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
} catch (EncodingException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
} catch (InterruptedException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|