11 #include <boost/asio.hpp> 12 #include <boost/bind.hpp> 13 #include <pion/error.hpp> 14 #include <pion/process.hpp> 15 #include <pion/tcp/server.hpp> 28 static const std::string HELLO_MESSAGE(
"Hello there!\x0D\x0A");
29 tcp_conn->set_lifecycle(pion::tcp::connection::LIFECYCLE_CLOSE);
30 tcp_conn->async_write(boost::asio::buffer(HELLO_MESSAGE),
38 int main (
int argc,
char *argv[])
40 static const unsigned int DEFAULT_PORT = 8080;
43 unsigned int port = DEFAULT_PORT;
45 port = strtoul(argv[1], 0, 10);
46 if (port == 0) port = DEFAULT_PORT;
47 }
else if (argc != 1) {
48 std::cerr <<
"usage: helloserver [port]" << std::endl;
53 process::initialize();
56 logger main_log(PION_GET_LOGGER(
"helloserver"));
57 logger pion_log(PION_GET_LOGGER(
"pion"));
58 PION_LOG_SETLEVEL_INFO(main_log);
59 PION_LOG_SETLEVEL_INFO(pion_log);
60 PION_LOG_CONFIG_BASIC;
65 tcp::server_ptr hello_server(
new HelloServer(port));
66 hello_server->start();
67 process::wait_for_shutdown();
69 }
catch (std::exception& e) {
70 PION_LOG_FATAL(main_log, pion::diagnostic_information(e));
virtual void handle_connection(const tcp::connection_ptr &tcp_conn)
simple TCP server that just sends "Hello there!" to each connection