Search in sources :

Example 1 with EzySocketStatus

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

the class EzySocketClient method processReceivedMessages.

protected void processReceivedMessages() {
    EzySocketStatus status = socketStatuses.last();
    if (status == EzySocketStatus.CONNECTED) {
        if (socketReader.isActive()) {
            processReceivedMessages0();
        }
    }
    EzySocketStatus statusLast = socketStatuses.last();
    if (isSocketDisconnectable(statusLast)) {
        if (socketReader.isStopped()) {
            onDisconnected(disconnectReason);
        } else if (socketWriter.isStopped()) {
            onDisconnected(disconnectReason);
        }
    }
}
Also used : EzySocketStatus(com.tvd12.ezyfoxserver.client.constant.EzySocketStatus)

Example 2 with EzySocketStatus

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

the class EzySocketClient method reconnect.

public boolean reconnect() {
    EzySocketStatus status = socketStatuses.last();
    if (!isSocketReconnectable(status)) {
        EzyLogger.warn("socket is not in a reconnectable status");
        return false;
    }
    int maxReconnectCount = reconnectConfig.getMaxReconnectCount();
    if (reconnectCount >= maxReconnectCount)
        return false;
    socketStatuses.push(EzySocketStatus.RECONNECTING);
    int reconnectSleepTime = reconnectConfig.getReconnectPeriod();
    connect0(reconnectSleepTime);
    reconnectCount++;
    EzyLogger.info("try reconnect to server: " + reconnectCount + ", wating time: " + reconnectSleepTime);
    EzyEvent tryConnectEvent = new EzyTryConnectEvent(reconnectCount);
    socketEventQueue.addEvent(tryConnectEvent);
    return true;
}
Also used : EzyEvent(com.tvd12.ezyfoxserver.client.event.EzyEvent) EzySocketStatus(com.tvd12.ezyfoxserver.client.constant.EzySocketStatus) EzyTryConnectEvent(com.tvd12.ezyfoxserver.client.event.EzyTryConnectEvent)

Example 3 with EzySocketStatus

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

the class EzySocketClient method processStatuses.

protected void processStatuses() {
    socketStatuses.popAll(localSocketStatuses);
    for (int i = 0; i < localSocketStatuses.size(); ++i) {
        EzySocketStatus status = localSocketStatuses.get(i);
        if (status == EzySocketStatus.CONNECTED) {
            EzyEvent evt = new EzyConnectionSuccessEvent();
            socketEventQueue.addEvent(evt);
        } else if (status == EzySocketStatus.CONNECT_FAILED) {
            EzyEvent evt = new EzyConnectionFailureEvent(connectionFailedReason);
            socketEventQueue.addEvent(evt);
            break;
        } else if (status == EzySocketStatus.DISCONNECTED) {
            EzyEvent evt = new EzyDisconnectionEvent(disconnectReason);
            socketEventQueue.addEvent(evt);
            break;
        }
    }
    localSocketStatuses.clear();
}
Also used : EzyEvent(com.tvd12.ezyfoxserver.client.event.EzyEvent) EzyDisconnectionEvent(com.tvd12.ezyfoxserver.client.event.EzyDisconnectionEvent) EzyConnectionFailureEvent(com.tvd12.ezyfoxserver.client.event.EzyConnectionFailureEvent) EzySocketStatus(com.tvd12.ezyfoxserver.client.constant.EzySocketStatus) EzyConnectionSuccessEvent(com.tvd12.ezyfoxserver.client.event.EzyConnectionSuccessEvent)

Example 4 with EzySocketStatus

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

the class EzySocketClient method connectTo.

public void connectTo(String host, int port) {
    EzySocketStatus status = socketStatuses.last();
    if (!isSocketConnectable(status)) {
        EzyLogger.warn("socket is connecting...");
        return;
    }
    this.socketStatuses.push(EzySocketStatus.CONNECTING);
    this.host = host;
    this.port = port;
    this.reconnectCount = 0;
    this.connect0(0);
}
Also used : EzySocketStatus(com.tvd12.ezyfoxserver.client.constant.EzySocketStatus)

Aggregations

EzySocketStatus (com.tvd12.ezyfoxserver.client.constant.EzySocketStatus)4 EzyEvent (com.tvd12.ezyfoxserver.client.event.EzyEvent)2 EzyConnectionFailureEvent (com.tvd12.ezyfoxserver.client.event.EzyConnectionFailureEvent)1 EzyConnectionSuccessEvent (com.tvd12.ezyfoxserver.client.event.EzyConnectionSuccessEvent)1 EzyDisconnectionEvent (com.tvd12.ezyfoxserver.client.event.EzyDisconnectionEvent)1 EzyTryConnectEvent (com.tvd12.ezyfoxserver.client.event.EzyTryConnectEvent)1