Ghost connections are the result of an incomplete socket disconnection which is not acknowledged by the server and can result in a few different problems: re-connecting users be refused because the server thinks that they are still online, the other players in the room will still see the disconnected user online etc...
In reality these pending connections are not fully closed, the TCP stack is still holding them and it's likely that several minutes will pass before the TCP timeout is fired and the connections are finally closed. When this happens the JVM is informed and finally SmartFoxServer can remove the owners of those connections.
The causes behind these "bad disconnections" can be multiple: an abrupt internet disconnection, the network cable being pulled, a crash in the browser or Flash plugin, a disconnection happening from a very slow and problematic connection, etc...
Since this problem is not avoidable SmartFoxServer provides several tools to deal with it:
-
User max idle time in Server Configurator module of the Admin Tool: allows you to specify the maximum amount a client can stay idle (not sending any requests) before being auto-disconnected. The server continuously monitors the connected user activity and attempts to kick the idle ones, including ghost-connections.
-
Session max idle time in Server Configurator module of the Admin Tool: this is similar to the previous one but it controls only those socket connections that haven't performed any login yet. This is useful for getting rid of idle connections coming from bots or any other "automated spiders" that scans the web for attackable services.
- Disconnect ghost user on login: create a server-side custom login handler as described
in this document and in the the login handler check if the user already exists, for example like this:
Code: Select all
public class LoginEventHandler extends BaseServerEventHandler
{
@Override
public void handleServerEvent(ISFSEvent event) throws SFSException
{
String name = (String) event.getParameter(SFSEventParam.LOGIN_NAME);
User user = getApi().getUserByName(name);
if (user != null)
{
trace("USER ALREADY EXISTING --> DISCONNECTING");
getApi().disconnectUser(user);
}
}
}