diff --git a/asio/src/Makefile.am b/asio/src/Makefile.am index cd215972..f5f48826 100644 --- a/asio/src/Makefile.am +++ b/asio/src/Makefile.am @@ -26,7 +26,9 @@ noinst_PROGRAMS = \ examples/tutorial/timer1/timer \ examples/tutorial/timer2/timer \ examples/tutorial/timer3/timer \ - examples/tutorial/timer4/timer + examples/tutorial/timer4/timer \ + examples/tutorial/daytime1/client \ + examples/tutorial/daytime2/server TESTS = \ tests/unit/demuxer_test \ @@ -66,6 +68,8 @@ examples_tutorial_timer1_timer_SOURCES = examples/tutorial/timer1/timer.cpp examples_tutorial_timer2_timer_SOURCES = examples/tutorial/timer2/timer.cpp examples_tutorial_timer3_timer_SOURCES = examples/tutorial/timer3/timer.cpp examples_tutorial_timer4_timer_SOURCES = examples/tutorial/timer4/timer.cpp +examples_tutorial_daytime1_client_SOURCES = examples/tutorial/daytime1/client.cpp +examples_tutorial_daytime2_server_SOURCES = examples/tutorial/daytime2/server.cpp EXTRA_DIST = \ Makefile.bor \ diff --git a/asio/src/Makefile.bor b/asio/src/Makefile.bor index 67a17eb1..7c733637 100644 --- a/asio/src/Makefile.bor +++ b/asio/src/Makefile.bor @@ -30,7 +30,9 @@ all: \ examples\tutorial\timer1\timer.exe \ examples\tutorial\timer2\timer.exe \ examples\tutorial\timer3\timer.exe \ - examples\tutorial\timer4\timer.exe + examples\tutorial\timer4\timer.exe \ + examples\tutorial\daytime1\client.exe \ + examples\tutorial\daytime2\server.exe check: all @tests\unit\demuxer_test.exe diff --git a/asio/src/Makefile.mgw b/asio/src/Makefile.mgw index e38ed436..d52a2b13 100644 --- a/asio/src/Makefile.mgw +++ b/asio/src/Makefile.mgw @@ -32,7 +32,9 @@ EXAMPLE_EXES = \ examples/tutorial/timer1/timer.exe \ examples/tutorial/timer2/timer.exe \ examples/tutorial/timer3/timer.exe \ - examples/tutorial/timer4/timer.exe + examples/tutorial/timer4/timer.exe \ + examples/tutorial/daytime1/client.exe \ + examples/tutorial/daytime2/server.exe all: $(TEST_EXES) $(EXAMPLE_EXES) diff --git a/asio/src/Makefile.msc b/asio/src/Makefile.msc index 8312a2d2..efb73238 100644 --- a/asio/src/Makefile.msc +++ b/asio/src/Makefile.msc @@ -30,7 +30,9 @@ all: \ examples\tutorial\timer1\timer.exe \ examples\tutorial\timer2\timer.exe \ examples\tutorial\timer3\timer.exe \ - examples\tutorial\timer4\timer.exe + examples\tutorial\timer4\timer.exe \ + examples\tutorial\daytime1\client.exe \ + examples\tutorial\daytime2\server.exe tests\performance\client.exe: tests\performance\client.obj tests\performance\server.exe: tests\performance\server.obj @@ -56,6 +58,8 @@ examples\tutorial\timer1\timer.exe: examples\tutorial\timer1\timer.obj examples\tutorial\timer2\timer.exe: examples\tutorial\timer2\timer.obj examples\tutorial\timer3\timer.exe: examples\tutorial\timer3\timer.obj examples\tutorial\timer4\timer.exe: examples\tutorial\timer4\timer.obj +examples\tutorial\daytime1\client.exe: examples\tutorial\daytime1\client.obj +examples\tutorial\daytime2\server.exe: examples\tutorial\daytime2\server.obj check: all @tests\unit\demuxer_test.exe && \ diff --git a/asio/src/examples/tutorial/daytime1/client.cpp b/asio/src/examples/tutorial/daytime1/client.cpp new file mode 100644 index 00000000..f030652c --- /dev/null +++ b/asio/src/examples/tutorial/daytime1/client.cpp @@ -0,0 +1,31 @@ +#include +#include "asio.hpp" + +int main(int argc, char* argv[]) +{ + try + { + if (argc != 2) + { + std::cerr << "Usage: client " << std::endl; + return 1; + } + + asio::demuxer demuxer; + + asio::stream_socket socket(demuxer); + + asio::socket_connector connector(demuxer); + connector.connect(socket, asio::ipv4::address(13, argv[1])); + + char buf[128]; + while (size_t len = socket.recv(buf, sizeof(buf))) + std::cout.write(buf, len); + } + catch (asio::socket_error& e) + { + std::cerr << e.what() << ": " << e.message() << std::endl; + } + + return 0; +} diff --git a/asio/src/examples/tutorial/daytime2/server.cpp b/asio/src/examples/tutorial/daytime2/server.cpp new file mode 100644 index 00000000..c7faba8c --- /dev/null +++ b/asio/src/examples/tutorial/daytime2/server.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include "asio.hpp" + +int main() +{ + try + { + asio::demuxer demuxer; + + asio::socket_acceptor acceptor(demuxer, asio::ipv4::address(13)); + + for (;;) + { + asio::stream_socket socket(demuxer); + acceptor.accept(socket); + + using namespace std; // For time_t, time and ctime. + time_t now = time(0); + std::string msg = ctime(&now); + + asio::send_n(socket, msg.c_str(), msg.length(), 0, asio::ignore_error()); + } + } + catch (asio::socket_error& e) + { + std::cerr << e.what() << ": " << e.message() << std::endl; + } + + return 0; +}