views:

17

answers:

0

I have a c# client talking to a C++ TCP Server on Linux using boost. The client is able to send/rcv messages from the server but when I close the client and restart it again, the server abort. I am new to boost so any help would be great. Below is the code of my server.

void
TcpServer::handle_accept(Client* new_client, const boost::system::error_code& error)
      {
        std::cout << "@@@@In TcpServer handle_accept... \n";
        if (!error)
        {
          new_client->Start();
          clientList.push_back (new_client);
          new_client = new Client(m_io_service);
          m_acceptor.async_accept(new_client->Socket(),
              boost::bind(&TcpServer::handle_accept, this, new_client,
                boost::asio::placeholders::error));
        }
        else
        {
        std::cout << "In TcpServer handle accept error.....\n";
        delete new_client;
        }
      }

Client::Client(boost::asio::io_service& io_service) : m_socket(io_service)
{

}


void 
Client::Start()
{
    std::cout << "!!!!In Client Start.....\n";

      m_socket.async_read_some(boost::asio::buffer(m_data, max_length),
          boost::bind(&Client::process_read, this,
            boost::asio::placeholders::error,
            boost::asio::placeholders::bytes_transferred));

}

When I start the client the second time and when it tries to connect to the server, the server aborted. It didn't seem to get into handle_accept because the first cout is not shown in the window.