コード例 #1
0
ファイル: NetManager.cs プロジェクト: 252378189/Fenix
        public NetPeer CreatePeer(ulong remoteHostId, IPEndPoint addr, NetworkType netType)
        {
            var peer = GetPeerById(remoteHostId, netType);

            if (peer != null)
            {
                return(peer);
            }
            peer = NetPeer.Create(remoteHostId, addr, netType);
            if (peer == null)
            {
                return(null);
            }
            peer.OnClose     += OnClose;
            peer.OnReceive   += OnReceive;
            peer.OnException += OnException;
            if (netType == NetworkType.TCP)
            {
                tcpPeers[peer.ConnId] = peer;
            }
            else
            {
                kcpPeers[peer.ConnId] = peer;
            }
            peer.Register();
            return(peer);
        }
コード例 #2
0
        //kcp目前不支持epoll/kqueue/IOCP,所以只在客户端上用用
        public void RegisterKcp(Ukcp ukcp)
        {
            var id   = ukcp.GetUniqueId();
            var peer = NetPeer.Create(id, ukcp);

            channelPeers[peer.ConnId] = peer;
            Log.Info(string.Format("Incoming KCP id: {0}", id));
        }
コード例 #3
0
        public void RegisterChannel(IChannel channel)
        {
            var cid  = channel.Id.AsLongText();
            var id   = Basic.GenID32FromName(cid);
            var peer = NetPeer.Create(id, channel);

            channelPeers[id] = peer;
        }
コード例 #4
0
ファイル: NetManager.cs プロジェクト: 252378189/Fenix
        public NetPeer RegisterChannel(IChannel channel)
        {
            var cid  = channel.Id.AsLongText();
            var id   = Basic.GenID64FromName(cid);
            var peer = NetPeer.Create(id, channel);

            channelPeers[id] = peer;
            return(peer);
        }
コード例 #5
0
ファイル: NetManager.cs プロジェクト: dora-BYR/Fenix
        //kcp目前不支持epoll/kqueue/IOCP,所以只在客户端上用用
        public void RegisterKcp(Ukcp ukcp)
        {
            var cid  = ukcp.user().Channel.Id.AsLongText() + ukcp.user().Channel.LocalAddress.ToIPv4String() + ukcp.user().RemoteAddress.ToIPv4String();
            var id   = Basic.GenID32FromName(cid);
            var peer = NetPeer.Create(id, ukcp);

            channelPeers[peer.ConnId] = peer;
            Log.Info(string.Format("Incoming KCP id: {0}", id));
        }
コード例 #6
0
        public NetPeer RegisterChannel(IChannel ch)
        {
            //var cid = channel.Id.AsLongText();
            //var id = Basic.GenID64FromName(cid);
            var id   = ch.GetUniqueId();
            var peer = NetPeer.Create(id, ch);

            channelPeers[id] = peer;
            //RemotePeers.channelPeers[id] = peer;
            return(peer);
        }
コード例 #7
0
ファイル: NetManager.cs プロジェクト: 252378189/Fenix
        //peer connects to hosts(interprocesses)
        public NetPeer CreatePeer(string ip, int port, NetworkType netType)
        {
//#if !CLIENT
            var ep   = new IPEndPoint(IPAddress.Parse(ip), port);
            var addr = ep.ToString();

            var hostId = Global.IdManager.GetHostId(addr);

            if (hostId != 0)
            {
                return(Global.NetManager.GetPeerById(hostId, netType));
            }
//#endif

            var peer = NetPeer.Create(ep, netType);

            if (peer == null)
            {
                return(null);
            }

            peer.OnClose     += OnClose;
            peer.OnReceive   += OnReceive;
            peer.OnException += OnException;

            if (netType == NetworkType.TCP)
            {
                tcpPeers[peer.ConnId] = peer;
            }
            else
            {
                kcpPeers[peer.ConnId] = peer;
            }
            peer.Register();
            return(peer);
        }