From: Nelson, E. - 2 <eri...@ba...> - 2010-04-07 17:49:56
|
On Wednesday, April 07, 2010 11:11 AM Dean Michael Berris wrote: >A more complete listing would definitely help me debug it or reproduce at least. In my experience in the past, it wasn't possible to bind two sockets to the same port- it caused an error, which makes sense to me. I'm running this example on Windows XP with MSVC2008 Thanks Erik ******************** #include <boost/network/protocol/http/server.hpp> #include <boost/thread/thread.hpp> #include <iostream> namespace http = boost::network::http; struct goodbye_world { void operator() (http::server<goodbye_world>::request const &request, http::server<goodbye_world>::response &response) { response = http::server<goodbye_world>::response::stock_reply( http::server<goodbye_world>::response::ok, "Goodbye, World!"); } void log(...) {} }; struct ThreadServer { ThreadServer(const char* hostname, const char* port) : server(hostname, port, handler) {} goodbye_world handler; http::server<goodbye_world> server; void thread_func() { server.run(); } }; struct hello_world { void operator() (http::server<hello_world>::request const &request, http::server<hello_world>::response &response) { response = http::server<hello_world>::response::stock_reply( http::server<hello_world>::response::ok, "Hello, World!"); } void log(...) {} }; int main(int argc, char * argv[]) { try { ThreadServer thread_server("localhost", "3000"); boost::thread thread_(boost::bind(&ThreadServer::thread_func, boost::ref(thread_server))); hello_world handler; http::server<hello_world> server("localhost", "3000", handler); server.run(); thread_.join(); } catch (std::exception &e) { std::cerr << e.what() << std::endl; } } |