Search in sources :

Example 1 with EzyClientConfig

use of com.tvd12.ezyfoxserver.client.config.EzyClientConfig in project ezyfox-server-example by tvd12.

the class HelloWorldClient method setup.

protected EzyClient setup() {
    EzyClientConfig clientConfig = EzyClientConfig.builder().zoneName(ZONE_NAME).enableSSL().enableDebug().build();
    EzyClients clients = EzyClients.getInstance();
    EzyClient client = new EzyUTClient(clientConfig);
    clients.addClient(client);
    EzySetup setup = client.setup();
    setup.addEventHandler(EzyEventType.CONNECTION_SUCCESS, new EzyConnectionSuccessHandler());
    setup.addEventHandler(EzyEventType.CONNECTION_FAILURE, new EzyConnectionFailureHandler());
    setup.addDataHandler(EzyCommand.HANDSHAKE, new ExHandshakeEventHandler());
    setup.addDataHandler(EzyCommand.LOGIN, new ExLoginSuccessHandler());
    setup.addDataHandler(EzyCommand.APP_ACCESS, new ExAccessAppHandler());
    EzyAppSetup appSetup = setup.setupApp(APP_NAME);
    appSetup.addDataHandler("greet", new ChatGreetResponseHandler());
    appSetup.addDataHandler("secureChat", new SecureChatResponseHandler());
    appSetup.addDataHandler("chatAll", new EzyAppDataHandler<EzyData>() {

        @Override
        public void handle(EzyApp app, EzyData data) {
            System.out.println("chatAll: " + data);
        }
    });
    appSetup.addDataHandler("chat1", new EzyAppDataHandler<EzyData>() {

        @Override
        public void handle(EzyApp app, EzyData data) {
            System.out.println("chat1: " + data);
        }
    });
    appSetup.addDataHandler("chatToMe", new EzyAppDataHandler<EzyData>() {

        @Override
        public void handle(EzyApp app, EzyData data) {
            System.out.println("chatToMe: " + data);
        }
    });
    appSetup.addDataHandler("err", new EzyAppDataHandler<EzyData>() {

        @Override
        public void handle(EzyApp app, EzyData data) {
            System.out.println("error: " + data);
        }
    });
    return client;
}
Also used : EzyAppSetup(com.tvd12.ezyfoxserver.client.setup.EzyAppSetup) EzyClientConfig(com.tvd12.ezyfoxserver.client.config.EzyClientConfig) EzyClient(com.tvd12.ezyfoxserver.client.EzyClient) EzyData(com.tvd12.ezyfox.entity.EzyData) EzyUTClient(com.tvd12.ezyfoxserver.client.EzyUTClient) EzyApp(com.tvd12.ezyfoxserver.client.entity.EzyApp) EzySetup(com.tvd12.ezyfoxserver.client.setup.EzySetup) EzyClients(com.tvd12.ezyfoxserver.client.EzyClients)

Example 2 with EzyClientConfig

use of com.tvd12.ezyfoxserver.client.config.EzyClientConfig in project ezyfox-server-example by tvd12.

the class HelloWorldClientUdp method setup.

protected EzyClient setup() {
    EzyClientConfig clientConfig = EzyClientConfig.builder().zoneName(ZONE_NAME).enableSSL().enableDebug().build();
    EzyClients clients = EzyClients.getInstance();
    EzyClient client = new EzyUTClient(clientConfig);
    clients.addClient(client);
    EzySetup setup = client.setup();
    setup.addEventHandler(EzyEventType.CONNECTION_SUCCESS, new EzyConnectionSuccessHandler());
    setup.addEventHandler(EzyEventType.CONNECTION_FAILURE, new EzyConnectionFailureHandler());
    setup.addDataHandler(EzyCommand.HANDSHAKE, new ExHandshakeEventHandler());
    setup.addDataHandler(EzyCommand.LOGIN, new ExLoginSuccessHandler());
    setup.addDataHandler(EzyCommand.UDP_HANDSHAKE, new ExHandshakeSuccessHandler());
    setup.addDataHandler(EzyCommand.APP_ACCESS, new ExAccessAppHandler());
    EzyAppSetup appSetup = setup.setupApp(APP_NAME);
    appSetup.addDataHandler("greet", new ChatGreetResponseHandler());
    appSetup.addDataHandler("udpGreet", (EzyAppDataHandler<EzyData>) (app, data) -> System.out.println("udpGreet: " + data));
    appSetup.addDataHandler("secureChat", new SecureChatResponseHandler());
    appSetup.addDataHandler("chatAll", (EzyAppDataHandler<EzyData>) (app, data) -> System.out.println("chatAll: " + data));
    appSetup.addDataHandler("chat1", (EzyAppDataHandler<EzyData>) (app, data) -> System.out.println("chat1: " + data));
    appSetup.addDataHandler("chatToMe", (EzyAppDataHandler<EzyData>) (app, data) -> System.out.println("chatToMe: " + data));
    appSetup.addDataHandler("err", (EzyAppDataHandler<EzyData>) (app, data) -> System.out.println("error: " + data));
    return client;
}
Also used : EzyApp(com.tvd12.ezyfoxserver.client.entity.EzyApp) com.tvd12.ezyfoxserver.client.handler(com.tvd12.ezyfoxserver.client.handler) EzyData(com.tvd12.ezyfox.entity.EzyData) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyClients(com.tvd12.ezyfoxserver.client.EzyClients) EzyRequest(com.tvd12.ezyfoxserver.client.request.EzyRequest) EzyAppAccessRequest(com.tvd12.ezyfoxserver.client.request.EzyAppAccessRequest) EzyStrings(com.tvd12.ezyfox.io.EzyStrings) HashMap(java.util.HashMap) EzySetup(com.tvd12.ezyfoxserver.client.setup.EzySetup) EzyUTClient(com.tvd12.ezyfoxserver.client.EzyUTClient) EzyLoginRequest(com.tvd12.ezyfoxserver.client.request.EzyLoginRequest) PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) EzyClient(com.tvd12.ezyfoxserver.client.EzyClient) EzyClientConfig(com.tvd12.ezyfoxserver.client.config.EzyClientConfig) EzyAppSetup(com.tvd12.ezyfoxserver.client.setup.EzyAppSetup) EzyEventType(com.tvd12.ezyfoxserver.client.event.EzyEventType) EzyMainEventsLoop(com.tvd12.ezyfoxserver.client.socket.EzyMainEventsLoop) EzyObject(com.tvd12.ezyfox.entity.EzyObject) Map(java.util.Map) EzyEntityObjects(com.tvd12.ezyfox.util.EzyEntityObjects) EzyCommand(com.tvd12.ezyfoxserver.client.constant.EzyCommand) HttpClient(com.tvd12.ezyhttp.client.HttpClient) EzyAppSetup(com.tvd12.ezyfoxserver.client.setup.EzyAppSetup) EzyClientConfig(com.tvd12.ezyfoxserver.client.config.EzyClientConfig) EzyClient(com.tvd12.ezyfoxserver.client.EzyClient) EzyData(com.tvd12.ezyfox.entity.EzyData) EzyUTClient(com.tvd12.ezyfoxserver.client.EzyUTClient) EzySetup(com.tvd12.ezyfoxserver.client.setup.EzySetup) EzyClients(com.tvd12.ezyfoxserver.client.EzyClients)

Example 3 with EzyClientConfig

use of com.tvd12.ezyfoxserver.client.config.EzyClientConfig in project ezyfox-server-android-client by youngmonkeys.

the class EzyConnectionFailureHandler method handle.

@Override
public final void handle(EzyConnectionFailureEvent event) {
    EzyLogger.info("connection failure, reason = " + event.getReason());
    EzyClientConfig config = client.getConfig();
    EzyReconnectConfig reconnectConfig = config.getReconnect();
    boolean shouldReconnect = shouldReconnect(event);
    boolean mustReconnect = reconnectConfig.isEnable() && shouldReconnect;
    boolean reconnecting = false;
    client.setStatus(EzyConnectionStatus.FAILURE);
    if (mustReconnect)
        reconnecting = client.reconnect();
    if (reconnecting) {
        onReconnecting(event);
    } else {
        onConnectionFailed(event);
    }
    postHandle(event);
}
Also used : EzyClientConfig(com.tvd12.ezyfoxserver.client.config.EzyClientConfig) EzyReconnectConfig(com.tvd12.ezyfoxserver.client.config.EzyReconnectConfig)

Example 4 with EzyClientConfig

use of com.tvd12.ezyfoxserver.client.config.EzyClientConfig in project ezyfox-server-example by tvd12.

the class SimpleChatClient method setup.

protected EzyClient setup() {
    EzyClientConfig clientConfig = EzyClientConfig.builder().zoneName(ZONE_NAME).build();
    EzyClients clients = EzyClients.getInstance();
    EzyClient client = new EzyUTClient(clientConfig);
    clients.addClient(client);
    EzySetup setup = client.setup();
    setup.addEventHandler(EzyEventType.CONNECTION_SUCCESS, new EzyConnectionSuccessHandler());
    setup.addEventHandler(EzyEventType.CONNECTION_FAILURE, new EzyConnectionFailureHandler());
    setup.addDataHandler(EzyCommand.HANDSHAKE, new ExHandshakeEventHandler());
    setup.addDataHandler(EzyCommand.LOGIN, new ExLoginSuccessHandler());
    setup.addDataHandler(EzyCommand.APP_ACCESS, new ExAccessAppHandler());
    EzyAppSetup appSetup = setup.setupApp(APP_NAME);
    appSetup.addDataHandler("chat/sendMessage", new ChatSendMessageResponseHandler());
    appSetup.addDataHandler("greet", new ChatGreetResponseHandler());
    appSetup.addDataHandler("hello", new ChatHelloResponseHandler());
    return client;
}
Also used : EzyAppSetup(com.tvd12.ezyfoxserver.client.setup.EzyAppSetup) EzyClientConfig(com.tvd12.ezyfoxserver.client.config.EzyClientConfig) EzyClient(com.tvd12.ezyfoxserver.client.EzyClient) EzyConnectionFailureHandler(com.tvd12.ezyfoxserver.client.handler.EzyConnectionFailureHandler) EzyUTClient(com.tvd12.ezyfoxserver.client.EzyUTClient) EzySetup(com.tvd12.ezyfoxserver.client.setup.EzySetup) EzyConnectionSuccessHandler(com.tvd12.ezyfoxserver.client.handler.EzyConnectionSuccessHandler) EzyClients(com.tvd12.ezyfoxserver.client.EzyClients)

Example 5 with EzyClientConfig

use of com.tvd12.ezyfoxserver.client.config.EzyClientConfig in project ezyfox-server-android-client by youngmonkeys.

the class EzyDisconnectionHandler method handle.

@Override
public final void handle(EzyDisconnectionEvent event) {
    String reasonName = EzyDisconnectReasons.getDisconnectReasonName(event.getReason());
    EzyLogger.info("handle disconnection, reason: " + reasonName);
    preHandle(event);
    EzyClientConfig config = client.getConfig();
    EzyReconnectConfig reconnectConfig = config.getReconnect();
    boolean shouldReconnect = shouldReconnect(event);
    boolean mustReconnect = reconnectConfig.isEnable() && event.getReason() != EzyDisconnectReason.UNAUTHORIZED.getId() && event.getReason() != EzyDisconnectReason.CLOSE.getId() && shouldReconnect;
    boolean reconnecting = false;
    client.setStatus(EzyConnectionStatus.DISCONNECTED);
    if (mustReconnect)
        reconnecting = client.reconnect();
    if (reconnecting) {
        onReconnecting(event);
    } else {
        onDisconnected(event);
    }
    postHandle(event);
}
Also used : EzyClientConfig(com.tvd12.ezyfoxserver.client.config.EzyClientConfig) EzyReconnectConfig(com.tvd12.ezyfoxserver.client.config.EzyReconnectConfig)

Aggregations

EzyClientConfig (com.tvd12.ezyfoxserver.client.config.EzyClientConfig)5 EzyClient (com.tvd12.ezyfoxserver.client.EzyClient)3 EzyClients (com.tvd12.ezyfoxserver.client.EzyClients)3 EzyUTClient (com.tvd12.ezyfoxserver.client.EzyUTClient)3 EzyAppSetup (com.tvd12.ezyfoxserver.client.setup.EzyAppSetup)3 EzySetup (com.tvd12.ezyfoxserver.client.setup.EzySetup)3 EzyData (com.tvd12.ezyfox.entity.EzyData)2 EzyReconnectConfig (com.tvd12.ezyfoxserver.client.config.EzyReconnectConfig)2 EzyApp (com.tvd12.ezyfoxserver.client.entity.EzyApp)2 EzyArray (com.tvd12.ezyfox.entity.EzyArray)1 EzyObject (com.tvd12.ezyfox.entity.EzyObject)1 EzyStrings (com.tvd12.ezyfox.io.EzyStrings)1 EzyEntityObjects (com.tvd12.ezyfox.util.EzyEntityObjects)1 EzyCommand (com.tvd12.ezyfoxserver.client.constant.EzyCommand)1 EzyEventType (com.tvd12.ezyfoxserver.client.event.EzyEventType)1 com.tvd12.ezyfoxserver.client.handler (com.tvd12.ezyfoxserver.client.handler)1 EzyConnectionFailureHandler (com.tvd12.ezyfoxserver.client.handler.EzyConnectionFailureHandler)1 EzyConnectionSuccessHandler (com.tvd12.ezyfoxserver.client.handler.EzyConnectionSuccessHandler)1 EzyAppAccessRequest (com.tvd12.ezyfoxserver.client.request.EzyAppAccessRequest)1 EzyLoginRequest (com.tvd12.ezyfoxserver.client.request.EzyLoginRequest)1