Pass host and port to NDN constructor and Transport::connect
diff --git a/ndn-cpp/NDN.cpp b/ndn-cpp/NDN.cpp
index 4f7be39..c41f1d7 100644
--- a/ndn-cpp/NDN.cpp
+++ b/ndn-cpp/NDN.cpp
@@ -18,7 +18,7 @@
vector<unsigned char> encoding;
interest.encode(encoding);
- transport_->connect((char *)"E.hub.ndn.ucla.edu", 9695);
+ transport_->connect(host_.c_str(), port_);
transport_->send(&encoding[0], encoding.size());
}
diff --git a/ndn-cpp/NDN.hpp b/ndn-cpp/NDN.hpp
index 09dfad2..c574b8d 100644
--- a/ndn-cpp/NDN.hpp
+++ b/ndn-cpp/NDN.hpp
@@ -11,14 +11,15 @@
#include "transport/Transport.hpp"
#include "encoding/BinaryXMLElementReader.hpp"
+using namespace std;
+
namespace ndn {
class NDN : public ElementListener {
public:
- NDN(const ptr_lib::shared_ptr<Transport> &transport, const ptr_lib::shared_ptr<Closure> &tempClosure)
+ NDN(const ptr_lib::shared_ptr<Transport> &transport, const char *host, unsigned short port, const ptr_lib::shared_ptr<Closure> &tempClosure)
+ : transport_(transport), host_(host), port_(port), tempClosure_(tempClosure)
{
- transport_ = transport;
- tempClosure_ = tempClosure;
}
/**
@@ -38,6 +39,8 @@
private:
ptr_lib::shared_ptr<Transport> transport_;
+ string host_;
+ unsigned short port_;
ptr_lib::shared_ptr<Closure> tempClosure_;
};
diff --git a/ndn-cpp/transport/TcpTransport.cpp b/ndn-cpp/transport/TcpTransport.cpp
index 7a3a190..c3abab6 100644
--- a/ndn-cpp/transport/TcpTransport.cpp
+++ b/ndn-cpp/transport/TcpTransport.cpp
@@ -10,10 +10,10 @@
namespace ndn {
-void TcpTransport::connect(char *host, unsigned short port)
+void TcpTransport::connect(const char *host, unsigned short port)
{
ndn_Error error;
- if (error = ndn_TcpTransport_connect(&transport_, host, port))
+ if (error = ndn_TcpTransport_connect(&transport_, (char *)host, port))
throw std::runtime_error(ndn_getErrorString(error));
}
diff --git a/ndn-cpp/transport/TcpTransport.hpp b/ndn-cpp/transport/TcpTransport.hpp
index a8a354e..a5d0ca8 100644
--- a/ndn-cpp/transport/TcpTransport.hpp
+++ b/ndn-cpp/transport/TcpTransport.hpp
@@ -18,7 +18,7 @@
ndn_TcpTransport_init(&transport_);
}
- virtual void connect(char *host, unsigned short port);
+ virtual void connect(const char *host, unsigned short port);
virtual void send(unsigned char *data, unsigned int dataLength);
diff --git a/ndn-cpp/transport/Transport.cpp b/ndn-cpp/transport/Transport.cpp
index 950b1cb..84a4e02 100644
--- a/ndn-cpp/transport/Transport.cpp
+++ b/ndn-cpp/transport/Transport.cpp
@@ -10,7 +10,7 @@
namespace ndn {
-void Transport::connect(char *host, unsigned short port)
+void Transport::connect(const char *host, unsigned short port)
{
throw logic_error("unimplemented");
}
diff --git a/ndn-cpp/transport/Transport.hpp b/ndn-cpp/transport/Transport.hpp
index 85fe1b7..655ce6e 100644
--- a/ndn-cpp/transport/Transport.hpp
+++ b/ndn-cpp/transport/Transport.hpp
@@ -10,7 +10,7 @@
class Transport {
public:
- virtual void connect(char *host, unsigned short port);
+ virtual void connect(const char *host, unsigned short port);
virtual void send(unsigned char *data, unsigned int dataLength);
diff --git a/tests/test-get-async.cpp b/tests/test-get-async.cpp
index 8965c54..85273ba 100644
--- a/tests/test-get-async.cpp
+++ b/tests/test-get-async.cpp
@@ -35,7 +35,7 @@
int main(int argc, char** argv)
{
try {
- NDN ndn(ptr_lib::make_shared<TcpTransport>(), ptr_lib::make_shared<MyClosure>());
+ NDN ndn(ptr_lib::make_shared<TcpTransport>(), "E.hub.ndn.ucla.edu", 9695, ptr_lib::make_shared<MyClosure>());
ndn.expressInterest(Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt/level2/%FD%05%0B%16%7D%95%0E"), ptr_lib::make_shared<MyClosure>(), 0);
ndn_BinaryXMLElementReader elementReader;