blob: 1acf65fe24a36dcef02694aa7d034cf6a1773b7d [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>
Jeff Thompson53412192013-08-06 13:35:50 -07009#include <ndn-cpp/interest.hpp>
Jeff Thompson56ec9e22013-08-02 11:34:07 -070010#include <ndn-cpp/data.hpp>
Jeff Thompson53412192013-08-06 13:35:50 -070011#include <ndn-cpp/transport/udp-transport.hpp>
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070012#include <ndn-cpp/face.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:
Jeff Thompsonb002f902013-07-16 18:07:18 -070020 MyClosure()
21 : gotContent_(false)
22 {
23 }
24
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070025 virtual UpcallResult upcall(UpcallKind kind, UpcallInfo &upcallInfo)
26 {
Jeff Thompson56ec9e22013-08-02 11:34:07 -070027 if (kind == UPCALL_DATA || kind == UPCALL_DATA_UNVERIFIED) {
Jeff Thompsonb002f902013-07-16 18:07:18 -070028 gotContent_ = true;
Jeff Thompson56ec9e22013-08-02 11:34:07 -070029 cout << "Got data packet with name " << upcallInfo.getData()->getName().to_uri() << endl;
30 for (unsigned int i = 0; i < upcallInfo.getData()->getContent().size(); ++i)
31 cout << upcallInfo.getData()->getContent()[i];
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070032 cout << endl;
33
34 return CLOSURE_RESULT_OK;
35 }
36 else
37 return CLOSURE_RESULT_OK;
38 }
Jeff Thompsonb002f902013-07-16 18:07:18 -070039
40 bool gotContent_;
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070041};
42
Jeff Thompsonc98be1a2013-07-14 22:44:43 -070043int main(int argc, char** argv)
44{
45 try {
Jeff Thompson2a4724b2013-08-07 17:13:34 -070046 MyClosure closure;
Jeff Thompson7098dd62013-08-06 14:42:02 -070047 Face face("E.hub.ndn.ucla.edu", 9695, shared_ptr<UdpTransport>(new UdpTransport()));
Jeff Thompson2a4724b2013-08-07 17:13:34 -070048 face.expressInterest(Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt/level2/%FD%05%0B%16%7D%95%0E"), &closure);
Jeff Thompson3a217062013-07-14 23:37:42 -070049
Jeff Thompsonb002f902013-07-16 18:07:18 -070050 // Pump the receive process. This should really be done by a socket listener.
Jeff Thompson2a4724b2013-08-07 17:13:34 -070051 while (!closure.gotContent_)
Jeff Thompson7098dd62013-08-06 14:42:02 -070052 face.getTransport()->tempReceive();
Jeff Thompson1bbc4e72013-07-16 16:30:55 -070053 } catch (std::exception &e) {
Jeff Thompsonc98be1a2013-07-14 22:44:43 -070054 cout << "exception: " << e.what() << endl;
55 }
56 return 0;
57}