Start adding new tutorial programs based around the daytime protocol.

This commit is contained in:
chris 2004-04-08 08:18:26 +00:00
parent b78173d8e0
commit 3e7c9641ec
6 changed files with 79 additions and 4 deletions

View File

@ -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 \

View File

@ -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

View File

@ -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)

View File

@ -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 && \

View File

@ -0,0 +1,31 @@
#include <iostream>
#include "asio.hpp"
int main(int argc, char* argv[])
{
try
{
if (argc != 2)
{
std::cerr << "Usage: client <host>" << 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;
}

View File

@ -0,0 +1,32 @@
#include <ctime>
#include <iostream>
#include <string>
#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;
}