mirror of
https://github.com/kierankihn/uno-game.git
synced 2025-12-27 02:13:18 +08:00
fix(network): call accept on NetworkServer initialization and after player addition
- Ensure `accept` is called during `NetworkServer` initialization and after successfully adding a player to handle new connections continuously.
This commit is contained in:
@@ -60,6 +60,7 @@ namespace UNO::NETWORK {
|
|||||||
this->acceptor_.async_accept([this](const asio::error_code &ec, asio::ip::tcp::socket socket) {
|
this->acceptor_.async_accept([this](const asio::error_code &ec, asio::ip::tcp::socket socket) {
|
||||||
if (!ec) {
|
if (!ec) {
|
||||||
this->addPlayer(std::move(socket));
|
this->addPlayer(std::move(socket));
|
||||||
|
accept();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -67,6 +68,7 @@ namespace UNO::NETWORK {
|
|||||||
NetworkServer::NetworkServer(uint16_t port, std::function<void(size_t, std::string)> callback) :
|
NetworkServer::NetworkServer(uint16_t port, std::function<void(size_t, std::string)> callback) :
|
||||||
acceptor_(io_context_, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port)), playerCount(0), callback_(std::move(callback))
|
acceptor_(io_context_, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port)), playerCount(0), callback_(std::move(callback))
|
||||||
{
|
{
|
||||||
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkServer::addPlayer(asio::ip::tcp::socket socket)
|
void NetworkServer::addPlayer(asio::ip::tcp::socket socket)
|
||||||
|
|||||||
Reference in New Issue
Block a user