boost : server tcp (mode synchrone)

Hello everybody,

I succed to make a server (tcp) with boost, and I can communicate between my server and my client. But when my client is disconnected, my server crashes. I want when my client is disconnected, that my server looks for an other client but it doesn't work.

this is my code :
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
    boost::asio::io_service ios;
    tcp::acceptor acceptor(ios, tcp::endpoint(tcp::v4(), 30000));
    char buffer[256];
 
    tcp::socket socket(ios);
 
    while(1){
    	std::cout << "wait client..." << std::endl;
    	acceptor.accept(socket);
    	std::cout << "Client connected ! " << std::endl;	
 
    	while (acceptor.is_open())
	    {
	    	try{
	    		boost::asio::read(socket, boost::asio::buffer(buffer));	
	    	}
	    	catch(std::exception& e){
 
	    		std::cout << "client left" << std::endl;
	    		acceptor.close();
	    		break;
	    	}
 
	        std::string message = buffer;
	        std::cout << "message received : " << message << std::endl;
	    }
    }


I have the error message : accept : already open

Can you help me ?

thanks for your help
the exeption return read: End of file.

I don't understand what is going on
Topic archived. No new replies allowed.