Beispiel #1
0
        /// <summary>
        /// 发送数据。发送时,默认在头部加上4字节的key
        /// </summary>
        /// <param name="buf"></param>
        public void Send(byte[] buf)
        {
            byte[] newbuf = new byte[buf.Length + 4];
            //把key附上,服务端合法性检测用
            KCPLib.ikcp_encode32u(newbuf, 0, (uint)m_Key);
            Array.Copy(buf, 0, newbuf, 4, buf.Length);

            m_Kcp.Send(newbuf);
            m_NeedUpdateFlag = true;
            var e = Event;

            if (e != null)
            {
                e(UdpClientEvents.Send, buf);
            }
        }
Beispiel #2
0
        //发送握手数据 16字节 8字节头+4字节index+4字节key
        private void SendHandshake()
        {
            if (UdpLibConfig.DebugLevel != (int)UdpLibLogLevel.None)
            {
#if DEBUG
                Console.WriteLine("发送握手数据");
#endif
            }

            Interlocked.Increment(ref m_pktCounter);
            byte[] buf = new byte[UdpLibConfig.HandshakeDataSize + 4];
            Array.Copy(UdpLibConfig.HandshakeHeadData, buf, UdpLibConfig.HandshakeHeadData.Length);
            KCPLib.ikcp_encode32u(buf, UdpLibConfig.HandshakeHeadData.Length, m_NetIndex);
            KCPLib.ikcp_encode32u(buf, UdpLibConfig.HandshakeHeadData.Length + 4, (uint)m_Key);
            KCPLib.ikcp_encode32u(buf, UdpLibConfig.HandshakeHeadData.Length + 8, (uint)m_pktCounter);
            m_UdpClient.Send(buf, buf.Length);
#if DEV
            string s = string.Format("{0},发送握手数据,{1}", m_NetIndex, m_pktCounter.ToString());
            IRQLog.AppLog.Log(s);
            Console.WriteLine(s);
#endif
        }