I think that the only way to get the real status of a socket, and therefore to discover a fall-down, is its usage.
A periodical transmission over the socket could be the key to check the end-to-end connectivity.
We can use the PingPong Request
provided by SmartFox API as application message for a periodical transmission.
As first thing
, I suggest to implement the PingPong Request in your Android application and then verify the behaviour disabling the routers connection to the internet.
Today Smartfox API uses a default value as socket transmission timeout.
In other words, the API will be notified about the failure of a socket transmission when the socket retries performed with the Operating System's default values will expire.
If PingPong Request on Android platform takes a long time to detect the unreachable status of SmartFox Server, we can think to extend API
to provide a new method that will be able to set a custom value for the socket transmission timeout.
As second thing
, I suggest to manually emulate this scenario. Please set a socket transmission timeout to investigate its behaviour with PingPong Request.
To get this goal please edit the TCPClient.cpp
file contained into Core\Sockets
Move at the end of the method
void TCPClient::OnBoostAsioConnect(const boost::system::error_code& code)
and add these statements
Code: Select all
// the timeout value
unsigned int timeout_milli = 3000;
// platform-specific switch
#if defined _WIN32 || defined WIN32 || defined OS_WIN64 || defined _WIN64 || defined WIN64 || defined WINNT
// use windows-specific time
int32_t timeout = timeout_milli;
setsockopt(boostTcpSocket.native(), SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout));
setsockopt(boostTcpSocket.native(), SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout));
// assume everything else is posix
struct timeval tv;
tv.tv_sec = timeout_milli / 1000;
tv.tv_usec = timeout_milli % 1000;
setsockopt(boostTcpSocket.native(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(boostTcpSocket.native(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
Please, let me know the result of your test