blob: 60b02b5df09ab1a74cc13ecb431ea04149219501 [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 Thompsonb9e3c8e2013-08-02 11:42:51 -070011#include <ndn-cpp/face.hpp>
Jeff Thompsonc98be1a2013-07-14 22:44:43 -070012
13using namespace std;
14using namespace ndn;
Jeff Thompson1bbc4e72013-07-16 16:30:55 -070015using namespace ptr_lib;
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070016
Jeff Thompson7aec0252013-08-22 17:29:57 -070017static int CallbackCount = 0;
18
19void myOnData(const ptr_lib::shared_ptr<const Interest> &interest, const ptr_lib::shared_ptr<Data> &data)
20{
21 ++CallbackCount;
22 cout << "Got data packet with name " << data->getName().to_uri() << endl;
23 for (unsigned int i = 0; i < data->getContent().size(); ++i)
24 cout << data->getContent()[i];
25 cout << endl;
26}
27
28void myOnTimeout(const ptr_lib::shared_ptr<const Interest> &interest)
29{
30 ++CallbackCount;
31 cout << "Time out for interest " << interest->getName().toUri() << endl;
32}
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070033
Jeff Thompsonc98be1a2013-07-14 22:44:43 -070034int main(int argc, char** argv)
35{
36 try {
Jeff Thompsondc461ab2013-08-19 18:15:59 -070037 Face face("E.hub.ndn.ucla.edu");
Jeff Thompson3a217062013-07-14 23:37:42 -070038
Jeff Thompson557b81e2013-08-21 15:13:51 -070039 Name name1("/ndn/ucla.edu/apps/ndn-js-test/hello.txt/level2/%FD%05%0B%16%7D%95%0E");
40 cout << "Express name " << name1.toUri() << endl;
Jeff Thompson7aec0252013-08-22 17:29:57 -070041 face.expressInterest(name1, myOnData, myOnTimeout);
42
Jeff Thompson557b81e2013-08-21 15:13:51 -070043 Name name2("/ndn/ucla.edu/apps/lwndn-test/howdy.txt/%FD%05%05%E8%0C%CE%1D");
44 cout << "Express name " << name2.toUri() << endl;
Jeff Thompson7aec0252013-08-22 17:29:57 -070045 face.expressInterest(name2, myOnData, myOnTimeout);
46
47 Name name3("/test/timeout");
48 cout << "Express name " << name3.toUri() << endl;
49 face.expressInterest(name3, myOnData, myOnTimeout);
Jeff Thompson557b81e2013-08-21 15:13:51 -070050
Jeff Thompson432c8be2013-08-09 16:16:08 -070051 // The main event loop.
Jeff Thompson7aec0252013-08-22 17:29:57 -070052 while (CallbackCount < 3) {
Jeff Thompsonc7e07442013-08-19 15:25:43 -070053 face.processEvents();
54 // We need to sleep for a few milliseconds so we don't use 100% of the CPU.
55 usleep(10000);
56 }
Jeff Thompson1bbc4e72013-07-16 16:30:55 -070057 } catch (std::exception &e) {
Jeff Thompsonc98be1a2013-07-14 22:44:43 -070058 cout << "exception: " << e.what() << endl;
59 }
60 return 0;
61}