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); } }
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); } }
/// <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); } }