Search in sources :

Example 1 with EzyClient

use of com.tvd12.ezyfoxserver.client.EzyClient 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 EzyClient

use of com.tvd12.ezyfoxserver.client.EzyClient 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 EzyClient

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

the class EzyMainEventsLoop method processEvents0.

protected void processEvents0() throws Exception {
    final List<EzyClient> cachedClients = new ArrayList<>();
    final EzyClients clients = EzyClients.getInstance();
    this.active = true;
    while (active) {
        Thread.sleep(3);
        uihandler.post(new Runnable() {

            @Override
            public void run() {
                clients.getClients(cachedClients);
                for (EzyClient one : cachedClients) one.processEvents();
            }
        });
    }
}
Also used : EzyClient(com.tvd12.ezyfoxserver.client.EzyClient) ArrayList(java.util.ArrayList) EzyClients(com.tvd12.ezyfoxserver.client.EzyClients)

Example 4 with EzyClient

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

the class SocketClientSetup method setup.

public void setup(EzyClient client, boolean useUdp) {
    int count = counter.incrementAndGet();
    EzySetup setup = client.setup();
    setup.addDataHandler(EzyCommand.HANDSHAKE, new HandshakeHandler(count));
    setup.addDataHandler(EzyCommand.LOGIN, new LoginSuccessHandler(useUdp));
    setup.addDataHandler(EzyCommand.UDP_HANDSHAKE, new UdpHandshakeHandler());
    setup.addDataHandler(EzyCommand.APP_ACCESS, new AccessAppHandler(useUdp, messageCount, executorService));
    EzyAppSetup appSetup = setup.setupApp("hello-world");
    appSetup.addDataHandler("broadcastMessage", (app, data) -> {
    // String message = ((EzyObject)data).get("message", String.class);
    // System.out.println("tcp > server response: " + message);
    });
    appSetup.addDataHandler("udpBroadcastMessage", (app, data) -> {
    // String message = ((EzyObject)data).get("message", String.class);
    // System.out.println("udp > server response: " + message);
    });
}
Also used : UdpHandshakeHandler(com.tvd12.ezyfoxserver.stresstest.handler.UdpHandshakeHandler) HandshakeHandler(com.tvd12.ezyfoxserver.stresstest.handler.HandshakeHandler) EzyAppSetup(com.tvd12.ezyfoxserver.client.setup.EzyAppSetup) UdpHandshakeHandler(com.tvd12.ezyfoxserver.stresstest.handler.UdpHandshakeHandler) LoginSuccessHandler(com.tvd12.ezyfoxserver.stresstest.handler.LoginSuccessHandler) EzySetup(com.tvd12.ezyfoxserver.client.setup.EzySetup) AccessAppHandler(com.tvd12.ezyfoxserver.stresstest.handler.AccessAppHandler)

Example 5 with EzyClient

use of com.tvd12.ezyfoxserver.client.EzyClient 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)

Aggregations

EzyClient (com.tvd12.ezyfoxserver.client.EzyClient)4 EzyClients (com.tvd12.ezyfoxserver.client.EzyClients)4 EzyAppSetup (com.tvd12.ezyfoxserver.client.setup.EzyAppSetup)4 EzySetup (com.tvd12.ezyfoxserver.client.setup.EzySetup)4 EzyUTClient (com.tvd12.ezyfoxserver.client.EzyUTClient)3 EzyClientConfig (com.tvd12.ezyfoxserver.client.config.EzyClientConfig)3 EzyData (com.tvd12.ezyfox.entity.EzyData)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 EzyRequest (com.tvd12.ezyfoxserver.client.request.EzyRequest)1