blob: fd2c1cc329d69dcf7ed03316166a97ac878763cb [file] [log] [blame]
Jeff Thompsonc98be1a2013-07-14 22:44:43 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6#include <cstdlib>
7#include <sstream>
8#include <iostream>
9#include <ndn-cpp/Interest.hpp>
10#include <ndn-cpp/ContentObject.hpp>
Jeff Thompson25f8e612013-07-15 11:30:21 -070011#include <ndn-cpp/transport/TcpTransport.hpp>
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070012#include <ndn-cpp/NDN.hpp>
Jeff Thompsonc98be1a2013-07-14 22:44:43 -070013
14using namespace std;
15using namespace ndn;
Jeff Thompson1bbc4e72013-07-16 16:30:55 -070016using namespace ptr_lib;
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070017
18class MyClosure : public Closure {
19public:
20 virtual UpcallResult upcall(UpcallKind kind, UpcallInfo &upcallInfo)
21 {
22 if (kind == UPCALL_CONTENT || kind == UPCALL_CONTENT_UNVERIFIED) {
23 cout << "Got content with name " << upcallInfo.getContentObject()->getName().to_uri() << endl;
24 for (unsigned int i = 0; i < upcallInfo.getContentObject()->getContent().size(); ++i)
25 cout << upcallInfo.getContentObject()->getContent()[i];
26 cout << endl;
27
28 return CLOSURE_RESULT_OK;
29 }
30 else
31 return CLOSURE_RESULT_OK;
32 }
33};
34
Jeff Thompsonc98be1a2013-07-14 22:44:43 -070035int main(int argc, char** argv)
36{
37 try {
Jeff Thompson1bbc4e72013-07-16 16:30:55 -070038 shared_ptr<TcpTransport> transport(new TcpTransport());
Jeff Thompson9657bda2013-07-16 16:23:41 -070039 NDN ndn(transport, "E.hub.ndn.ucla.edu", 9695);
Jeff Thompson1bbc4e72013-07-16 16:30:55 -070040 ndn.expressInterest(Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt/level2/%FD%05%0B%16%7D%95%0E"), make_shared<MyClosure>(), 0);
Jeff Thompson3a217062013-07-14 23:37:42 -070041
Jeff Thompson0cb7aee2013-07-16 16:18:06 -070042 transport->tempReceive();
Jeff Thompson1bbc4e72013-07-16 16:30:55 -070043 } catch (std::exception &e) {
Jeff Thompsonc98be1a2013-07-14 22:44:43 -070044 cout << "exception: " << e.what() << endl;
45 }
46 return 0;
47}