Skip to content

Commit

Permalink
disconnecting clients no longer breaks server, fixes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
zaphoyd committed Sep 15, 2011
1 parent 348214d commit e63bb79
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/chat_server/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ void chat_handler::disconnect(session_ptr client,uint16_t status,const std::stri

std::cout << "client " << client << " left the lobby." << std::endl;

const std::string alias = it->second;
m_connections.erase(it);

// send user list and signoff message to all clients
send_to_all(serialize_state());
send_to_all(encode_message("server",m_connections[client]+" has left the chat."));
send_to_all(encode_message("server",alias+" has left the chat."));
}

void chat_handler::message(session_ptr client,const std::string &msg) {
Expand Down Expand Up @@ -177,4 +178,4 @@ void chat_handler::send_to_all(std::string data) {
for (it = m_connections.begin(); it != m_connections.end(); it++) {
(*it).first->send(data);
}
}
}

0 comments on commit e63bb79

Please sign in to comment.