【问题标题】:Usage Of SFSEventType.SERVER_READY inSmartFox ServerSmartFox 服务器中 SFSEventType.SERVER_READY 的使用
【发布时间】:2014-07-02 09:12:32
【问题描述】:

我正在使用 SmartFox 服务器并想检查服务器是否已准备好接受请求。根据我在可用文档和 google 中的搜索。通过在服务器上使用事件处理程序说明哪个需要处理某种事件或触发该事件时需要执行的某个代码块..可以使用事件SERVER_READY..但是我如何向客户端发送响应是我坚持的..这是到目前为止的代码..

在我的扩展中..

addEventHandler(SFSEventType.SERVER_READY, ServerReadyHandler.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.. 

        }

    }

}

我的客户端在android java中...

【问题讨论】:

    标签: android smartfoxserver


    【解决方案1】:


    让我们考虑这些

    1. SERVER_READY 在每个扩展的 Smartfox 的整个生命周期中只会触发一次,因此您无法从那里向客户端触发任何事件。
    2. 客户端库的SmartFox类有以下方法和事件来判断服务器状态

       a) isConnected()
       b) isConnecting()
       c) SFSEvent.CONNECTION
       d) SFSEvent.CONNECTION_LOST
       e) SFSEvent.LOGIN
       f) SFSEvent.LOGIN_ERROR
      
    3. 这里的方法 a) b) 将指定 smartfox 服务器(不是您的扩展服务器)是否已连接。
    4. c),d) 事件将在 sfs.connect(ip,port);被客户解雇。
    5. 当客户端需要连接您的加入时,它会以 LoginRequest(username,password,zonename) 的形式向您的区域发送请求

    6. 如果您的区域未处于活动状态或没有具有该名称的区域,smartfox 会自动触发 SFSEVENT。Login_error 将触发。

    7. 如果您的区域处于活动状态,那么您的区域扩展的 SFSEventType.USER_LOGIN 将根据您的编码客户端触发,将获得 LOGIN/LOGIN_ERROR 事件之一。

    如果您需要示例代码,我会发送。请使用 smartfox 文档。

    【讨论】:

      猜你喜欢
      • 2011-11-20
      • 2013-12-17
      • 2012-07-31
      • 2014-05-07
      • 2014-11-21
      • 1970-01-01
      • 2013-04-11
      • 1970-01-01
      • 2016-03-31
      相关资源
      最近更新 更多