Original Post
Hey, I have a problem detecting disconnect when the network cable is pulled.
Every 60 seconds i send out a "heartbeat" packet from server to all connected clients, which in our protocol is a payload and crc (8 bytes)
The client does nothing with this packet.
the server is using async_write
boost::asio::async_write(m_Socket, asyncData, boost::bind(&net::BoostConnection::HandleWrite, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, ptr_tmp_cast(this)));
void net::BoostConnection::HandleWrite(const boost::system::error_code& errorCode, size_t bytesWritten, Ptr_c self)
Even when the network cable is unplugged, i get successfull writes in the HandleWrite callback. errorCode is is not set to indicate peer errors, and the amount of bytes written is 8, as expected.
The server is initalized like this:
bool net::NetServerBase::Start(unsigned short port)
{
boost::system::error_code errorCode;
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), port);
m_Acceptor.open(endpoint.protocol());
m_Acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
m_Acceptor.set_option(boost::asio::ip::tcp::no_delay(true));
if ( m_Acceptor.bind( endpoint, errorCode) )
{
.....
}
The async accept initalizes socket with these socket options:
m_Socket.set_option(boost::asio::ip::tcp::no_delay(true));
m_Socket.set_option(boost::asio::socket_base::reuse_address(true));
Are there any more options i need to set so a timeout is detected earlier? I thought that if cable was pulled and I sent data, i would get an immidiate response that the data failed. obviously I am either doing something wrong, or have misunderstood something!
Any help would be appriciated!
Every 60 seconds i send out a "heartbeat" packet from server to all connected clients, which in our protocol is a payload and crc (8 bytes)
The client does nothing with this packet.
the server is using async_write
boost::asio::async_write(m_Socket, asyncData, boost::bind(&net::BoostConnection::HandleWrite, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, ptr_tmp_cast(this)));
void net::BoostConnection::HandleWrite(const boost::system::error_code& errorCode, size_t bytesWritten, Ptr_c
Even when the network cable is unplugged, i get successfull writes in the HandleWrite callback. errorCode is is not set to indicate peer errors, and the amount of bytes written is 8, as expected.
The server is initalized like this:
bool net::NetServerBase::Start(unsigned short port)
{
boost::system::error_code errorCode;
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), port);
m_Acceptor.open(endpoint.protocol());
m_Acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
m_Acceptor.set_option(boost::asio::ip::tcp::no_delay(true));
if ( m_Acceptor.bind( endpoint, errorCode) )
{
.....
}
The async accept initalizes socket with these socket options:
m_Socket.set_option(boost::asio::ip::tcp::no_delay(true));
m_Socket.set_option(boost::asio::socket_base::reuse_address(true));
Are there any more options i need to set so a timeout is detected earlier? I thought that if cable was pulled and I sent data, i would get an immidiate response that the data failed. obviously I am either doing something wrong, or have misunderstood something!
Any help would be appriciated!