Add example client

This commit is contained in:
str4d
2017-04-02 11:34:23 +12:00
parent d56e6d11f9
commit 8443bda2b0
4 changed files with 36 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.o
*.a
eepget

View File

@ -7,5 +7,9 @@ TARGET=libi2psam.a
$(TARGET): $(OBJS)
$(AR) $(ARFLAGS) $(TARGET) $(OBJS)
LOADLIBES=-L./ -li2psam
eepget: eepget.cpp $(TARGET)
clean:
$(RM) $(TARGET) $(OBJS)
$(RM) $(TARGET) $(OBJS) eepget

View File

@ -9,3 +9,5 @@ Pre-release (ongoing refactoring work and migration to C++11)
## Usage
Copy the files into your codebase, or build and link to the library.
See `eepget.cpp` for example client usage (build with `make eepget`).

28
eepget.cpp Normal file
View File

@ -0,0 +1,28 @@
// Copyright (c) 2017 The I2P Project
// Distributed under the MIT software license, see the accompanying
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
//--------------------------------------------------------------------------------------------------
#include "i2psam.h"
#include <iostream>
int main(int argc, char **argv)
{
if (argc < 2) {
std::cerr << "Usage: eepget <hostname.i2p>" << std::endl;
return 1;
}
std::string target(argv[1]);
SAM::StreamSession s("eepget");
auto lookupResult = s.namingLookup(target);
auto connResult = s.connect(lookupResult.value, false);
auto conn = connResult.value.get();
conn->write("GET / HTTP/1.1\r\n\r\n");
auto reply = conn->read();
while (!reply.empty()) {
std::cout << reply << std::flush;
reply = conn->read();
}
conn->close();
}