Exemplo n.º 1
0
 public bool Connect(string _host, int _port)
 {
     this.Close();
     host     = _host;
     port     = _port;
     m_socket = this.NewSocket();
     m_socket.Reset(host, port);
     m_state = NetAgentState.Connecting;
     return(m_socket.ConnectAsync(OnSocketOpen, OnSocketRecvData, OnSocketClose));
 }
Exemplo n.º 2
0
        void OnSocketClose()
        {
            m_state     = NetAgentState.Closed;
            m_error_num = m_socket.GetErrorNum();
            m_error_msg = m_socket.GetErrorMsg();
            if (null != m_handler)
            {
                m_handler.OnClose(m_error_num, m_error_msg);
            }

            AppLog.Info("OnSocketClose");
        }
Exemplo n.º 3
0
        void OnSocketOpen(bool isSucc)
        {
            m_state = isSucc ? NetAgentState.Connected : NetAgentState.Closed;

            if (null != m_handler)
            {
                m_handler.OnOpen(isSucc);
            }
            if (!isSucc)
            {
                this.Close();
            }

            AppLog.Info("OnSocketOpen");
        }
Exemplo n.º 4
0
        protected override void OnUpdate()
        {
            base.OnUpdate();

            List <ulong> toRemoveAgentIds = new List <ulong>();
            var          tmpAgents        = new Dictionary <ulong, NetAgentBase>(m_netAgents);

            foreach (var kvPair in tmpAgents)
            {
                ulong        id = kvPair.Key;
                NetAgentBase na = kvPair.Value;

                NetAgentState curr_state = na.GetState();
                if (NetAgentState.Closed == curr_state || NetAgentState.Free == curr_state)
                {
                    toRemoveAgentIds.Add(id);
                }
                na.UpdateIO();
            }
            foreach (ulong id in toRemoveAgentIds)
            {
                RemoveNetAgent(id);
            }
        }