From fa4f4a8a50c4bab3a3e247fb7186a7f9a00dfc11 Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Mon, 3 Dec 2007 10:51:16 +0000 Subject: Added syncsocket --- Sockets/tests/http.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Sockets/tests/http.cpp (limited to 'Sockets/tests/http.cpp') diff --git a/Sockets/tests/http.cpp b/Sockets/tests/http.cpp new file mode 100644 index 0000000..6800699 --- /dev/null +++ b/Sockets/tests/http.cpp @@ -0,0 +1,65 @@ +#include +#include + + +class tSocket : public HTTPSocket +{ +public: + tSocket(ISocketHandler& h, const std::string& host) : HTTPSocket(h), m_host(host) + , m_first(false) + , m_sz(0) { + Open(host, 80); + } + + void OnConnect() { + Send("GET /index.html HTTP/1.0\r\n"); + Send("Host: " + m_host + "\r\n"); + Send("\r\n"); + } + + void OnFirst() { + } + + void OnHeader(const std::string& key, const std::string& value) { + fprintf(stderr, "%s: %s\n", key.c_str(), value.c_str()); + } + + void OnHeaderComplete() { + fprintf(stderr, "\n"); + } + + void OnData(const char *buf, size_t sz) { + if (1||!m_first) + { + std::string str = buf; + str.resize( sz ); + printf("%s", str.c_str()); + m_first = true; + } + m_sz += sz; + } + + void OnDelete() { + fprintf(stderr, "Content length: %d\n", m_sz); + } + +private: + std::string m_host; + bool m_first; + size_t m_sz; +}; + + +int main(int argc, char *argv[]) +{ + std::string host = argc > 1 ? argv[1] : "www.alhem.net"; + SocketHandler h; + tSocket sock(h, host); + h.Add(&sock); + while (h.GetCount()) + { + h.Select(1, 0); + } +} + + -- cgit v1.2.3