Ejemplo n.º 1
0
 HandleResult OnPrepareConnect(TcpClient sender, IntPtr socket)
 {
     lock (m_LockObject)
     {
         ClientSocketEvent e = new ClientSocketEvent();
         e.connId = this.ConnectionId;
         e.type   = ClientSocketEvent.CLIENTSOCKETEVENT_TYPE.ONPREPARECONNECT;
         m_Queue.Enqueue(e);
     }
     return(HandleResult.Ok);
 }
Ejemplo n.º 2
0
 HandleResult OnClose(TcpClient sender, SocketOperation enOperation, int errorCode)
 {
     lock (m_LockObject)
     {
         m_bConnect       = false;
         m_nReconnectTick = System.Environment.TickCount;
         ClientSocketEvent e = new ClientSocketEvent();
         e.connId = this.ConnectionId;
         e.type   = ClientSocketEvent.CLIENTSOCKETEVENT_TYPE.ONCLOSE;
         m_Queue.Enqueue(e);
     }
     return(HandleResult.Ok);
 }
Ejemplo n.º 3
0
 HandleResult OnReceive(TcpClient sender, byte[] bytes)
 {
     lock (m_LockObject)
     {
         ClientSocketEvent e = new ClientSocketEvent();
         e.connId = this.ConnectionId;
         e.type   = ClientSocketEvent.CLIENTSOCKETEVENT_TYPE.ONRECEIVE;
         e.data   = new byte[bytes.Length];
         Buffer.BlockCopy(bytes, 0, e.data, 0, bytes.Length);
         m_Queue.Enqueue(e);
     }
     return(HandleResult.Ok);
 }
Ejemplo n.º 4
0
        public void Run()
        {
            if (m_bStartConnect && !m_bConnect)
            {
                if (System.Environment.TickCount - m_nReconnectTick > m_nReconnectTime)
                {
                    if (m_TcpClient.Connect(m_sIP, m_nPort))
                    {
                        m_bConnect = true;
                    }
                    else
                    {
                        //永远不会走到这里的,黑人问号脸-。-
                        ClientSocketEvent e = new ClientSocketEvent();
                        e.connId = this.ConnectionId;
                        e.type   = ClientSocketEvent.CLIENTSOCKETEVENT_TYPE.ONRECONNECT;
                        m_OnSocket.Invoke(e);
                    }
                    m_nReconnectTick = System.Environment.TickCount;
                }
            }


            //交换数据队列
            lock (m_LockObject)
            {
                if (m_Queue.Count > 0)
                {
                    for (int i = 0; i < m_Queue.Count; i++)
                    {
                        m_TempQueue.Enqueue(m_Queue.Dequeue());
                    }
                }
            }
            if (m_TempQueue.Count > 0)
            {
                for (int i = 0; i < m_TempQueue.Count; i++)
                {
                    m_OnSocket.Invoke(m_TempQueue.Dequeue());
                }
            }
        }