Jeff Thompson | c98be1a | 2013-07-14 22:44:43 -0700 | [diff] [blame] | 1 | /** |
| 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 Thompson | 25f8e61 | 2013-07-15 11:30:21 -0700 | [diff] [blame] | 11 | #include <ndn-cpp/transport/TcpTransport.hpp> |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame^] | 12 | #include <ndn-cpp/c/encoding/BinaryXMLElementReader.h> |
| 13 | #include <ndn-cpp/NDN.hpp> |
Jeff Thompson | c98be1a | 2013-07-14 22:44:43 -0700 | [diff] [blame] | 14 | |
| 15 | using namespace std; |
| 16 | using namespace ndn; |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame^] | 17 | |
| 18 | class MyClosure : public Closure { |
| 19 | public: |
| 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 Thompson | c98be1a | 2013-07-14 22:44:43 -0700 | [diff] [blame] | 35 | int main(int argc, char** argv) |
| 36 | { |
| 37 | try { |
| 38 | Interest interest; |
| 39 | interest.getName() = Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt/level2/%FD%05%0B%16%7D%95%0E"); |
| 40 | vector<unsigned char> encoding; |
| 41 | interest.encode(encoding); |
| 42 | |
Jeff Thompson | 25f8e61 | 2013-07-15 11:30:21 -0700 | [diff] [blame] | 43 | TcpTransport transport; |
| 44 | transport.connect((char *)"E.hub.ndn.ucla.edu", 9695); |
| 45 | transport.send(&encoding[0], encoding.size()); |
Jeff Thompson | c98be1a | 2013-07-14 22:44:43 -0700 | [diff] [blame] | 46 | |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame^] | 47 | MyClosure closure; |
| 48 | NDN ndn(&closure); |
Jeff Thompson | 3a21706 | 2013-07-14 23:37:42 -0700 | [diff] [blame] | 49 | |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame^] | 50 | ndn_BinaryXMLElementReader elementReader; |
| 51 | ndn_BinaryXMLElementReader_init(&elementReader, (struct ndn_ElementListener *)&ndn); |
| 52 | |
| 53 | unsigned char buffer[8000]; |
| 54 | unsigned int nBytes = transport.receive(buffer, sizeof(buffer)); |
| 55 | ndn_BinaryXMLElementReader_onReceivedData(&elementReader, buffer, nBytes); |
Jeff Thompson | c98be1a | 2013-07-14 22:44:43 -0700 | [diff] [blame] | 56 | } catch (exception &e) { |
| 57 | cout << "exception: " << e.what() << endl; |
| 58 | } |
| 59 | return 0; |
| 60 | } |