Search in sources :

Example 1 with EzyClients

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

the class TcpSocketStresstest method main.

public static void main(String[] args) throws Exception {
    DefaultClientConfig clientConfig = new DefaultClientConfig();
    SocketClientSetup setup = new SocketClientSetup("websocket");
    EzyClients clients = EzyClients.getInstance();
    new Thread(() -> {
        int clientCount = 300;
        for (int i = 0; i < clientCount; i++) {
            EzyTcpClient client = new EzyTcpClient(clientConfig.get(i));
            try {
                Thread.sleep(50);
            } catch (Exception e) {
                e.printStackTrace();
            }
            setup.setup(client, false);
            clients.addClient(client);
            client.connect("127.0.0.1", 3005);
        }
    }).start();
    EzyMainEventsLoop mainEventsLoop = new EzyMainEventsLoop();
    mainEventsLoop.start(5);
}
Also used : EzyTcpClient(com.tvd12.ezyfoxserver.client.EzyTcpClient) EzyClients(com.tvd12.ezyfoxserver.client.EzyClients) EzyMainEventsLoop(com.tvd12.ezyfoxserver.client.socket.EzyMainEventsLoop)

Example 2 with EzyClients

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

the class UdpSocketStresstest method main.

public static void main(String[] args) throws Exception {
    DefaultClientConfig clientConfig = new DefaultClientConfig();
    SocketClientSetup setup = new SocketClientSetup("websocket");
    EzyClients clients = EzyClients.getInstance();
    new Thread(() -> {
        int clientCount = 500;
        for (int i = 0; i < clientCount; i++) {
            EzyTcpClient client = new EzyUTClient(clientConfig.get(i));
            try {
                Thread.sleep(50);
            } catch (Exception e) {
                e.printStackTrace();
            }
            setup.setup(client, true);
            clients.addClient(client);
            client.connect("127.0.0.1", 3005);
        }
    }).start();
    EzyMainEventsLoop mainEventsLoop = new EzyMainEventsLoop();
    mainEventsLoop.start(5);
}
Also used : EzyTcpClient(com.tvd12.ezyfoxserver.client.EzyTcpClient) EzyUTClient(com.tvd12.ezyfoxserver.client.EzyUTClient) EzyClients(com.tvd12.ezyfoxserver.client.EzyClients) EzyMainEventsLoop(com.tvd12.ezyfoxserver.client.socket.EzyMainEventsLoop)

Example 3 with EzyClients

use of com.tvd12.ezyfoxserver.client.EzyClients 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 4 with EzyClients

use of com.tvd12.ezyfoxserver.client.EzyClients 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 5 with EzyClients

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

Aggregations

EzyClients (com.tvd12.ezyfoxserver.client.EzyClients)7 EzyClient (com.tvd12.ezyfoxserver.client.EzyClient)4 EzyUTClient (com.tvd12.ezyfoxserver.client.EzyUTClient)4 EzyMainEventsLoop (com.tvd12.ezyfoxserver.client.socket.EzyMainEventsLoop)4 EzyClientConfig (com.tvd12.ezyfoxserver.client.config.EzyClientConfig)3 EzyAppSetup (com.tvd12.ezyfoxserver.client.setup.EzyAppSetup)3 EzySetup (com.tvd12.ezyfoxserver.client.setup.EzySetup)3 EzyData (com.tvd12.ezyfox.entity.EzyData)2 EzyTcpClient (com.tvd12.ezyfoxserver.client.EzyTcpClient)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 EzyWsClient (com.tvd12.ezyfoxserver.client.EzyWsClient)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