Asio multiple request

If i use this code for setting up a simple web browser, i can acess it once with firefox. now i want acess it multiple, can somebody help me?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <boost/asio.hpp> 
#include <string> 

boost::asio::io_service io_service; 
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 80); 
boost::asio::ip::tcp::acceptor acceptor(io_service, endpoint); 
boost::asio::ip::tcp::socket sock(io_service); 
std::string data = "HTTP/1.1 200 OK\r\nContent-Length: 13\r\n\r\nHello, world!"; 

void write_handler(const boost::system::error_code &ec, std::size_t bytes_transferred) 
{ 
} 

void accept_handler(const boost::system::error_code &ec) 
{ 
  if (!ec) 
  { 
    boost::asio::async_write(sock, boost::asio::buffer(data), write_handler); 

  } 
} 

int main() 
{ 
  acceptor.listen(); 
  acceptor.async_accept(sock, accept_handler); 
  io_service.run(); 
} 
Hi
Have no idea about boost, never used
Your write handler does nothing and returns. Once it returns, your main thread exits the run() and the program terminates. You should always have an async request pending, or alternatively a work object. That is covered in the asio tutorial http://www.boost.org/doc/libs/release/doc/html/boost_asio/tutorial.html

Also, look at the examples http://www.boost.org/doc/libs/release/doc/html/boost_asio/examples.html -- almost all of them allow multiple incoming connections.
yes, multiple request works now, but if i use this code
http://www.boost.org/doc/libs/1_48_0/doc/html/boost_asio/tutorial/tutdaytime3/src.html
and change the port 13 to the http port 80, it sometimes work, but then firefox cant load the page.
its complete random,if it works or not.
any idea, how i can fix this?
Topic archived. No new replies allowed.