public EzyClient newClient(EzyClientConfig config)
 {
     lock (clients)
     {
         return(newClient0(config));
     }
 }
    private SocketClientProxy()
    {
        this.username = "******";
        this.password = "******";
        firstLogin    = true;
        var config = EzyClientConfig.builder()
                     .clientName(ZONE_NAME)
                     .build();

        socketClient = new EzyUTClient(config);
        EzyClients.getInstance().addClient(socketClient);
        var setup = socketClient.setup();

        setup.addEventHandler(EzyEventType.CONNECTION_SUCCESS, new EzyConnectionSuccessHandler());
        setup.addEventHandler(EzyEventType.CONNECTION_FAILURE, new EzyConnectionFailureHandler());
        setup.addEventHandler(EzyEventType.DISCONNECTION, new DisconnectionHandler());
        setup.addDataHandler(EzyCommand.HANDSHAKE, new HandshakeHandler());
        setup.addDataHandler(EzyCommand.LOGIN, new LoginSuccessHandler());
        setup.addDataHandler(EzyCommand.LOGIN_ERROR, new EzyLoginErrorHandler());
        setup.addDataHandler(EzyCommand.APP_ACCESS, new AppAccessHandler());
        setup.addDataHandler(EzyCommand.UDP_HANDSHAKE, new UdpHandshakeHandler());
        var appSetup = setup.setupApp(APP_NAME);

        appSetup.addDataHandler("reconnect", new ReconnectResponseHandler());
        appSetup.addDataHandler("getGameId", new GetGameIdResponseHandler());
        appSetup.addDataHandler("startGame", new StartGameResponseHandler());
        appAccessed = false;
    }
        protected override void process(EzyDisconnectionEvent evt)
        {
            String reasonName = EzyDisconnectReasons.getDisconnectReasonName(evt.getReason());

            logger.info("handle disconnection, reason = " + reasonName);
            preHandle(evt);
            EzyClientConfig    config          = client.getConfig();
            EzyReconnectConfig reconnectConfig = config.getReconnect();
            bool should        = shouldReconnect(evt);
            bool mustReconnect = reconnectConfig.isEnable() &&
                                 evt.getReason() != (int)EzyDisconnectReason.UNAUTHORIZED &&
                                 evt.getReason() != (int)EzyDisconnectReason.CLOSE &&
                                 should;
            bool reconnecting = false;

            client.setStatus(EzyConnectionStatus.DISCONNECTED);
            client.setUdpStatus(EzyConnectionStatus.DISCONNECTED);
            if (mustReconnect)
            {
                reconnecting = client.reconnect();
            }
            if (reconnecting)
            {
                onReconnecting(evt);
            }
            else
            {
                onDisconnected(evt);
            }
            postHandle(evt);
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            Thread.CurrentThread.Name = "main";

            new BindingExample().Run();
            new EntityExample().Run();
            new DateTimeExample().Run();

            EzyLoggerFactory.setLoggerLevel(EzyLoggerLevel.DEBUG);

            EzyClientConfig clientConfig = EzyClientConfig
                                           .builder()
                                           .clientName("freetanks")
                                           .zoneName("example")
                                           .build();
            EzyClients clients = EzyClients.getInstance();
            //EzyClient client = clients.newDefaultClient(clientConfig);
            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.addEventHandler(EzyEventType.DISCONNECTION, new EzyDisconnectionHandler());
            setup.addDataHandler(EzyCommand.HANDSHAKE, new ExHandshakeEventHandler());
            setup.addDataHandler(EzyCommand.LOGIN, new ExLoginSuccessHandler());
            //setup.addDataHandler(EzyCommand.LOGIN_ERROR, new ExLoginErrorHandler());
            setup.addDataHandler(EzyCommand.APP_ACCESS, new ExAccessAppHandler());
            setup.addDataHandler(EzyCommand.UDP_HANDSHAKE, new UdpHandshakeHandler());

            EzyAppSetup appSetup = setup.setupApp("hello-world");

            //appSetup.addDataHandler(Commands.ERROR, new ErrorResponseHandler());
            appSetup.addDataHandler(Commands.ACCESS_LOBBY_ROOM, new AccessLobbyResponseHandler());
            appSetup.addDataHandler(Commands.ROOM_INFO, new RoomInfoResponseHandler());
            appSetup.addDataHandler(Commands.SYNC_POSITION, new SyncPositionHandler());

            client.connect("ws.tvd12.com", 3005);
            //client.connect("127.0.0.1", 3005);

            int time = 0;

            while (true)
            {
                Thread.Sleep(3);
                client.processEvents();
                time += 3;
                if (time > 5000)
                {
                    //client.disconnect(401);
                    time = 0;
                    //break;
                }
            }

            //mainEventsLoopTest();
        }
 public EzyClient newDefaultClient(EzyClientConfig config)
 {
     lock (clients)
     {
         EzyClient client = newClient0(config);
         defaultClientName = client.getName();
         return(client);
     }
 }
Beispiel #6
0
 public EzyTcpClient(EzyClientConfig config)
 {
     this.config             = config;
     this.name               = config.getClientName();
     this.status             = EzyConnectionStatus.NULL;
     this.status             = EzyConnectionStatus.NULL;
     this.pingManager        = new EzySimplePingManager(config.getPing());
     this.pingSchedule       = new EzyPingSchedule(this);
     this.handlerManager     = new EzySimpleHandlerManager(this);
     this.networkStatistics  = new EzySimpleStatistics();
     this.requestSerializer  = new EzySimpleRequestSerializer();
     this.settingUp          = new EzySimpleSetup(handlerManager);
     this.unloggableCommands = newUnloggableCommands();
     this.socketClient       = newSocketClient();
     this.logger             = EzyLoggerFactory.getLogger(GetType());
 }
        private EzyClient newClient0(EzyClientConfig config)
        {
            String clientName = config.getClientName();

            if (clients.ContainsKey(clientName))
            {
                return(clients[clientName]);
            }
            EzyClient client = new EzyTcpClient(config);

            addClient0(client);
            if (defaultClientName == null)
            {
                defaultClientName = client.getName();
            }
            return(client);
        }
        protected override sealed void process(EzyConnectionFailureEvent evt)
        {
            logger.info("connection failure, reason = " + evt.getReason());
            EzyClientConfig    config          = client.getConfig();
            EzyReconnectConfig reconnectConfig = config.getReconnect();
            bool should        = shouldReconnect(evt);
            bool mustReconnect = reconnectConfig.isEnable() && should;
            bool reconnecting  = false;

            client.setStatus(EzyConnectionStatus.FAILURE);
            if (mustReconnect)
            {
                reconnecting = client.reconnect();
            }
            if (reconnecting)
            {
                onReconnecting(evt);
            }
            else
            {
                onConnectionFailed(evt);
            }
            postHandle(evt);
        }
Beispiel #9
0
 public EzyUTClient(EzyClientConfig config) : base(config)
 {
 }