blob: 69a51e4430731f3c4a917321fbe9b69c0e2ff4b2 [file] [log] [blame]
Alexander Afanasyevc4b75982014-01-09 14:51:45 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
Alexander Afanasyev09c613f2014-01-29 00:23:58 -08008// correct way to include NDN-CPP headers
9// #include <ndn-cpp-dev/face.hpp>
10#include "face.hpp"
11
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080012void
13onData(ndn::Face &face,
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080014 const ndn::Interest& interest, ndn::Data& data)
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080015{
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080016 std::cout << "I: " << interest.toUri() << std::endl;
17 std::cout << "D: " << data.getName().toUri() << std::endl;
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080018}
19
20void
21onTimeout(ndn::Face &face,
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080022 const ndn::Interest& interest)
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080023{
24 std::cout << "Timeout" << std::endl;
25}
26
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080027int main()
28{
29 try {
30 ndn::Interest i(ndn::Name("/localhost/testApp/randomData"));
31 i.setScope(1);
32 i.setInterestLifetime(1000);
33 i.setMustBeFresh(true);
34
35 ndn::Face face;
36 face.expressInterest(i,
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080037 ndn::bind(onData, boost::ref(face), _1, _2),
38 ndn::bind(onTimeout, boost::ref(face), _1));
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080039
40 // processEvents will block until the requested data received or timeout occurs
41 face.processEvents();
42 }
43 catch(std::exception &e) {
44 std::cerr << "ERROR: " << e.what() << std::endl;
45 }
46 return 0;
47}