Project

General

Profile

Bug #3607 » consumer.cpp

The consumer - Michael Sweatt, 04/25/2016 02:59 PM

 
1
#include <ndn-cxx/face.hpp>
2
#include <ndn-cxx/security/key-chain.hpp>
3

    
4
namespace ndn {
5

    
6
class Consumer : noncopyable
7
{
8
public:
9
  void
10
  run()
11
  {
12
    Interest interest(Name("/NTORRENT/foo/bar.txt/%FE%00/%FE%00/sha256digest=f4446686f2c9fd94d0d24b26eae465600547c1b37afdfca6abf026849dad0cda"));
13
    interest.setInterestLifetime(time::milliseconds(1000));
14
    interest.setMustBeFresh(true);
15

    
16
    m_face.expressInterest(interest,
17
                           bind(&Consumer::onData, this,  _1, _2),
18
                           bind(&Consumer::onTimeout, this, _1));
19

    
20
    std::cout << "Sending " << interest << std::endl;
21

    
22
    // processEvents will block until the requested data received or timeout occurs
23
    m_face.processEvents();
24
  }
25

    
26
private:
27
  void
28
  onData(const Interest& interest, const Data& data)
29
  {
30
    std::cout << data << std::endl;
31
  }
32

    
33
  void
34
  onTimeout(const Interest& interest)
35
  {
36
    std::cout << "Timeout " << interest << std::endl;
37
  }
38

    
39
private:
40
  Face m_face;
41
};
42

    
43
} // namespace ndn
44

    
45
int
46
main(int argc, char** argv)
47
{
48
  ndn::Consumer consumer;
49
  try {
50
    consumer.run();
51
  }
52
  catch (const std::exception& e) {
53
    std::cerr << "ERROR: " << e.what() << std::endl;
54
  }
55
  return 0;
56
}
(1-1/3)