Beispiel #1
0
        public void DoReceiveInThread(byte[] buffer, int size)
        {
            if (NetDebuger.IsPacketLoss())
            {
                return;
            }

            byte[] dst = new byte[size];
            Buffer.BlockCopy(buffer, 0, dst, 0, size);
            m_RecvQueue.Push(dst);
        }
Beispiel #2
0
        public int SendTo(byte[] buffer, int size, IPEndPoint remoteEP)
        {
            int cnt = 0;

            if (NetDebuger.IsPacketLoss())
            {
                return(0);
            }

            //如果无法使用LocalSocket再使用SystemSocket
            if (cnt == 0)
            {
                cnt = m_SystemSocket.SendTo(buffer, 0, size, SocketFlags.None, remoteEP);
            }

            return(cnt);
        }
Beispiel #3
0
        //------------------------------------------------------------
        #region ReceiveFrom和SendTo函数
        public int ReceiveFrom(byte[] buffer, int maxsize, ref IPEndPoint remoteEP)
        {
            int cnt = 0;

            EndPoint ip = null;

            if (!m_EnableBlockOnRecv)
            {
                if (m_SystemSocket.Available <= 0)
                {
                    return(0);
                }
            }


            if (m_AddrFamily == AddressFamily.InterNetwork)
            {
                //如果是IPv4环境,则(与Android的处理一样)
                ip  = IPUtils.GetIPEndPointAny(AddressFamily.InterNetwork, 0);
                cnt = m_SystemSocket.ReceiveFrom(buffer, maxsize, SocketFlags.None, ref ip);

                if (cnt > 0 && remoteEP != null && !remoteEP.Equals(ip))
                {
                    Debuger.LogWarning(LOG_TAG, "ReceiveFrom() 收到一个自来陌生IP:Port(" + ip + ")的数据包!");
                    return(0);
                }
            }
            else
            {
                //如果是IPv6环境,则:
                ip  = remoteEP;
                cnt = m_SystemSocket.ReceiveFrom(buffer, maxsize, SocketFlags.None, ref ip);
            }

            remoteEP = ip as IPEndPoint;

            if (NetDebuger.IsPacketLoss())
            {
                return(0);
            }

            return(cnt);
        }