I am using the boost library to implement a socket communication. In respect to my main application, a connection handler should be launched who deals with all incoming requests.
Therefore I have encapsulated the whole server handler into the class server. When the server object is created it should launch the server.
However this way the thread dies with the execution end of the constructor code. I guess I don't get how boost / posix threads work. I come from a Java background.
server::server(int port) {
try {
boost::asio::io_service io_service;
tcp_server server(io_service, port);
boost::thread t(boost::bind(&boost::asio::io_service::run, &io_service));
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}