summaryrefslogtreecommitdiffstats
path: root/ml/dlib/examples/iosockstream_ex.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:19:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:20:02 +0000
commit58daab21cd043e1dc37024a7f99b396788372918 (patch)
tree96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /ml/dlib/examples/iosockstream_ex.cpp
parentReleasing debian version 1.43.2-1. (diff)
downloadnetdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz
netdata-58daab21cd043e1dc37024a7f99b396788372918.zip
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ml/dlib/examples/iosockstream_ex.cpp')
-rw-r--r--ml/dlib/examples/iosockstream_ex.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/ml/dlib/examples/iosockstream_ex.cpp b/ml/dlib/examples/iosockstream_ex.cpp
new file mode 100644
index 000000000..8a5dbbb24
--- /dev/null
+++ b/ml/dlib/examples/iosockstream_ex.cpp
@@ -0,0 +1,47 @@
+// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
+/*
+
+ This is an example illustrating the use of the iosockstream object from the
+ dlib C++ Library.
+
+ This program simply connects to www.google.com at port 80 and requests the
+ main Google web page. It then prints what it gets back from Google to the
+ screen.
+
+
+ For those of you curious about HTTP check out the excellent introduction at
+ http://www.jmarshall.com/easy/http/
+*/
+
+#include <dlib/iosockstream.h>
+#include <iostream>
+
+using namespace std;
+using namespace dlib;
+
+int main()
+{
+ try
+ {
+ // Connect to Google's web server which listens on port 80. If this
+ // fails it will throw a dlib::socket_error exception.
+ iosockstream stream("www.google.com:80");
+
+ // At this point, we can use stream the same way we would use any other
+ // C++ iostream object. So to test it out, let's make a HTTP GET request
+ // for the main Google page.
+ stream << "GET / HTTP/1.0\r\n\r\n";
+
+ // Here we print each character we get back one at a time.
+ while (stream.peek() != EOF)
+ {
+ cout << (char)stream.get();
+ }
+ }
+ catch (exception& e)
+ {
+ cout << e.what() << endl;
+ }
+}
+
+