Beispiel #1
0
        public void OnAccept(int sock, int protocol)
        {
            mAcceptSock = sock;

            if (protocol == 0)
            {
                mUdp              = new UdpService(this);
                mUdp.onConnect   += OnConnect;
                mUdp.onDisconnet += OnDisconnect;
                mUdp.onException += onException;
                mUdp.onMessage   += OnReceive;

                mUdp.Connect(mIP, mUDPPort);
            }
            else
            {
                mKcp              = new KcpService(this, (uint)mAcceptSock);
                mKcp.onConnect   += OnConnect;
                mKcp.onDisconnet += OnDisconnect;
                mKcp.onException += onException;
                mKcp.onMessage   += OnReceive;

                mKcp.Connect(mIP, mUDPPort);
            }
        }
Beispiel #2
0
 public NetworkService(int tcp, int udp, bool kcp)
 {
     mTcp = new TcpService(this, tcp);
     if (kcp)
     {
         mKcp = new KcpService(this, udp);
     }
     else
     {
         mUdp = new UdpService(this, udp);
     }
 }
Beispiel #3
0
        /// <summary>
        /// 选择性连接UDP服务器或者KCP服务器
        /// </summary>
        /// <param name="sock"></param>
        /// <param name="protocol"></param>
        public void OnAccept(int sock, Protocol protocol)
        {
            mAcceptSock = sock;

            if (protocol == Protocol.UDP)
            {
                mUdp = new UdpService();
                mUdp.Connect(mIP, mUDPPort);
            }
            else
            {
                mKcp = new KcpService((uint)mAcceptSock);
                mKcp.Connect(mIP, mUDPPort);
            }
        }