Hi.
I sort of have a server running but when there is 2 or more clients the sever crashes with a Debug Assertion Fail
in xstring line 78 what does that mean with in the following code.
the server app will send a predefind vector of messages to all clients when a button is pressed
Like so.
for(UINT ctr = 0; ctr < Messages.size(); ++ctr)
Lobby.deliver(Messages[ctr]);
if there is only one client it seams to work.
If I just send 1 message it all works can hold the send button down and it sends data no fails
Lobby.deliver(Messages[0]);
It must happen afer the data is sent because the 2 clients recieve the correct data.
where should I look.
I'm thinking it may be a race condition with the message and the async_write method.
both handle_write may return at the same time.
The Lobby Deliver Function
.
void deliver(const cMessage& msg)
{
//first time user of std::for_each
std::for_each(Clients.begin(), Clients.end(),
boost::bind(&cConnection::deliver, _1, boost::ref(msg)));
}
and the cConnections deliver that gets binded
.
void deliver(const cMessage& msg)
{
//the sever sends use messages by this
async_write(msg, boost::bind(&cSession::handle_write, this,
boost::asio::placeholders::error, shared_from_this()));
}
/// Handle completion of a write operation.
void handle_write(const boost::system::error_code& e, cConnection_ptr client)
{
// Nothing to do. The socket will be closed automatically when the last
// reference to the connection object goes away.
std::stringstream ss;
ss << "Server Handle Write Completed \n";
global_stream_lock.lock();
//send the data to the client list box
SendMessage(GlobalList, (UINT)LB_ADDSTRING , 0, (LPARAM) ss.str().c_str());
global_stream_lock.unlock();
if(!e)// && read_msg_.decode_header())
{
//std::cout << "Server Sent All DATA" << std::endl;
ss.str("");
ss.clear();
ss << "Server Sent All DATA";
global_stream_lock.lock();
//send the data to the client list box
SendMessage(GlobalList, (UINT)LB_ADDSTRING , 0, (LPARAM) ss.str().c_str());
global_stream_lock.unlock();
}
else
{
//std::cout << "Server Send Error = " << e.message << std::endl;
ss.str("");
ss.clear();
ss << "Server Send Error = " << e.message();
global_stream_lock.lock();
//send the data to the client list box
SendMessage(GlobalList, (UINT)LB_ADDSTRING , 0, (LPARAM) ss.str().c_str());
global_stream_lock.unlock();
ss.str("");
ss.clear();
ss << "Lost Client\nRemoving Client = FooBar";
global_stream_lock.lock();
//send the data to the client list box
SendMessage(GlobalList, (UINT)LB_ADDSTRING , 0, (LPARAM) ss.str().c_str());
global_stream_lock.unlock();
//will the lobby need to be protected by mute x lock or some other ????????????
//remove this client from the lobby its a dead client
Lobby.leave(shared_from_this());
}
}