重构代码,删除不必要的文件,添加控制数据包处理和Steam消息处理功能

This commit is contained in:
Ayndpa
2025-11-18 19:05:50 +08:00
parent 3b85a5f3bb
commit b308a644ff
11 changed files with 194 additions and 483 deletions

View File

@@ -43,9 +43,10 @@ void TCPClient::send(const std::string& message) {
void TCPClient::send(const char* data, size_t size) {
if (!connected_) return;
// std::cout << "Sending " << size << " bytes" << std::endl;
boost::asio::async_write(*socket_, boost::asio::buffer(data, size), [](const boost::system::error_code& error, std::size_t) {
boost::asio::async_write(*socket_, boost::asio::buffer(data, size), [this](const boost::system::error_code& error, std::size_t) {
if (error) {
std::cerr << "Send failed: " << error.message() << std::endl;
disconnect();
}
});
}
@@ -75,7 +76,11 @@ void TCPClient::handle_read(const boost::system::error_code& error, std::size_t
}
start_read();
} else {
std::cerr << "Read failed: " << error.message() << std::endl;
if (error == boost::asio::error::eof) {
std::cout << "Connection closed by peer" << std::endl;
} else {
std::cerr << "Read failed: " << error.message() << std::endl;
}
disconnect();
}
}