Ejemplo n.º 1
0
        //======================================================================
        //接收数据
        //======================================================================
        protected void DoReceiveInThread()
        {
            //子线程
            this.LogVerbose();

            bool result = false;

            try
            {
                EndPoint remotePoint = IPUtils.GetIPEndPointAny(AddressFamily.InterNetwork, 0);
                int      cnt         = m_socket.ReceiveFrom(m_RecvBufferTemp, m_RecvBufferTemp.Length, SocketFlags.None, ref remotePoint);

                if (cnt > 0)
                {
                    if (!RemoteEndPoint.Equals(remotePoint))
                    {
                        Debuger.LogVerbose("收到非目标服务器的数据!");
                        return;
                    }

                    m_bufferReceive.Attach(m_RecvBufferTemp, cnt);
                    byte[] m_32b = new byte[4];
                    m_bufferReceive.ReadBytes(m_32b, 0, 4);
                    uint sid = BitConverter.ToUInt32(m_32b, 0);

                    if (sid == 0)
                    {
                        //Session过期了
                        HandleServerError((int)NetErrorCode.SessionExpire);
                        return;
                    }

                    byte[] dst = new byte[cnt];
                    Buffer.BlockCopy(m_RecvBufferTemp, 0, dst, 0, cnt);

                    m_RecvBufQueue.Push(dst);
                }
            }
            catch (Exception ex)
            {
                this.LogWarning("接收数据出错:{0}", ex.Message);
                onReceiveError.InvokeSafe(this, (int)NetErrorCode.UnkownError, ex.Message);
            }
        }
 public bool Equals(TcpConnection connection)
 {
     return(LocalEndPoint.Equals(connection.LocalEndPoint) && RemoteEndPoint.Equals(connection.RemoteEndPoint));
 }