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); }
//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)); }
public void RegisterChannel(IChannel channel) { var cid = channel.Id.AsLongText(); var id = Basic.GenID32FromName(cid); var peer = NetPeer.Create(id, channel); channelPeers[id] = peer; }
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); }
//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)); }
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); }
//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); }