public bool reconnect()
        {
            EzySocketStatus status = socketStatuses.last();

            if (!isSocketReconnectable(status))
            {
                logger.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++;
            logger.info("try reconnect to server: " + reconnectCount + ", wating time: " + reconnectSleepTime);
            EzyEvent tryConnectEvent = new EzyTryConnectEvent(reconnectCount);

            socketEventQueue.addEvent(tryConnectEvent);
            return(true);
        }
        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);
                }
            }
        }
Beispiel #3
0
 protected void connect0()
 {
     try
     {
         clearAdapters();
         createAdapters();
         addNetworkStatisticsAdapers();
         updateAdapters();
         closeSocket();
         packetQueue.clear();
         socketStatuses.clear();
         datagramChannel = new UdpClient();
         datagramChannel.Connect(serverAddress.getHost(), serverAddress.getPort());
         startAdapters();
         socketStatuses.push(EzySocketStatus.CONNECTING);
         sendHandshakeRequest();
         Thread newThread = new Thread(() => {
             Thread.Sleep(3000);
             EzySocketStatus status = socketStatuses.last();
             if (status == EzySocketStatus.CONNECTING)
             {
                 socketStatuses.push(EzySocketStatus.CONNECT_FAILED);
             }
             reconnect();
         });
         newThread.Name = "udp-reconnect";
         newThread.Start();
     }
     catch (Exception e) {
         throw new EzyUdpConnectionException("udp can't connect to: " + serverAddress, e);
     }
 }
 protected void processStatuses()
 {
     socketStatuses.popAll(localSocketStatuses);
     for (int i = 0; i < localSocketStatuses.Count; ++i)
     {
         EzySocketStatus status = localSocketStatuses[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();
 }
Beispiel #5
0
        public void popReadMessages(IList <EzyArray> buffer)
        {
            EzySocketStatus status = socketStatuses.last();

            if (status == EzySocketStatus.CONNECTING || status == EzySocketStatus.CONNECTED)
            {
                this.socketReader.popMessages(buffer);
            }
        }
Beispiel #6
0
        public bool reconnect()
        {
            EzySocketStatus status = socketStatuses.last();

            if (status != EzySocketStatus.CONNECT_FAILED)
            {
                return(false);
            }
            logger.warn("udp socket is re-connecting...");
            connect0();
            return(true);
        }
Beispiel #7
0
        public void connectTo(String host, int port)
        {
            EzySocketStatus status = socketStatuses.last();

            if (!isSocketConnectable(status))
            {
                logger.warn("udp socket is connecting...");
                return;
            }
            serverAddress = new InetSocketAddress(host, port);
            connect0();
        }
        public void connectTo(String host, int port)
        {
            EzySocketStatus status = socketStatuses.last();

            if (!isSocketConnectable(status))
            {
                logger.warn("socket is connecting...");
                return;
            }
            this.socketStatuses.push(EzySocketStatus.CONNECTING);
            this.host           = host;
            this.port           = port;
            this.reconnectCount = 0;
            this.connect0(0);
        }
Beispiel #9
0
 public void udpSetStatus(EzySocketStatus status)
 {
     this.udpClient.setStatus(status);
 }
Beispiel #10
0
 public void setStatus(EzySocketStatus status)
 {
     socketStatuses.push(status);
 }