blob: a185386e2c1f03cdd957f662076a553dbaffa244 [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>
11#include <ndn-cpp/c/network/TcpTransport.h>
12
13using namespace std;
14using namespace ndn;
15int main(int argc, char** argv)
16{
17 try {
18 Interest interest;
19 interest.getName() = Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt/level2/%FD%05%0B%16%7D%95%0E");
20 vector<unsigned char> encoding;
21 interest.encode(encoding);
22
23 struct ndn_TcpTransport transport;
24 ndn_TcpTransport_init(&transport);
25 ndn_Error error;
26 if (error = ndn_TcpTransport_connect(&transport, (char *)"E.hub.ndn.ucla.edu", 9695))
27 return error;
28 if (error = ndn_TcpTransport_send(&transport, &encoding[0], encoding.size()))
29 return error;
30
31 unsigned char buffer[8000];
32 unsigned int nBytes;
33 while (1) {
34 if (error = ndn_TcpTransport_receive(&transport, buffer, sizeof(buffer), &nBytes))
35 return error;
36 if (buffer[0] == 0x04)
37 break;
38 }
39
40 for (int i = 0; i < nBytes; ++i)
41 printf("%02X ", (unsigned int)buffer[i]);
42
43 ContentObject contentObject;
44 contentObject.decode(buffer, nBytes);
45 } catch (exception &e) {
46 cout << "exception: " << e.what() << endl;
47 }
48 return 0;
49}