0

I am using SmartFox Server and want to check if the Server is ready to accept requests or not.According to my searchings in the available documentation and google..the way to do this by using a event handler on the server stating which kind of event needs to be handled or a certain block of code that needs to be executed when that event is fired..An event SERVER_READY is available to use..but how do i send a response to the client is what i am stuck at..this is the code so far..

In my extension..

addEventHandler(SFSEventType.SERVER_READY, ServerReadyHandler.class );

And the handler class..

public class ServerReadyHandler extends BaseServerEventHandler{

    MyExtension ade=null;
    ISFSObject resp_obj=null;

    @Override
    public void handleServerEvent(ISFSEvent event) throws SFSException 
    {
        ade=(AdminExtension) getParentExtension();


        if(event.getType().equals(SFSEventType.SERVER_READY))
        {
           // response needs to be send to the client that server is ready.. 

        }

    }

}

my client side is in android java...

AndroidMech
  • 1,676
  • 3
  • 20
  • 31

1 Answers1

1


Lets Consider these

  1. SERVER_READY will fire only once in entire lifecycle of Smartfox per extension, so you can't fire any event to client from there.
  2. SmartFox class of client library has following methods and events to determine server status

     a) isConnected()
     b) isConnecting()
     c) SFSEvent.CONNECTION
     d) SFSEvent.CONNECTION_LOST
     e) SFSEvent.LOGIN
     f) SFSEvent.LOGIN_ERROR
    
  3. here methods a) b) will specify whether the smartfox server(not your extension server) is connected or not.
  4. c),d) events will fire when ever the sfs.connect(ip,port); fired from client.
  5. When ever the client need to connect with your join it will sends a request to your zone as LoginRequest(username,password,zonename)

  6. if your zone is not in active or there is no zone with that name the smartfox automatically fires SFSEVENT.Login_error will fires.

  7. if your zone is active then your zone extension's SFSEventType.USER_LOGIN will fired according to your coding client will get either of LOGIN/LOGIN_ERROR events.

If you need the sample code then I will send. Please go with smartfox documentation.

RamBen
  • 990
  • 1
  • 9
  • 17