private void KcpServer_OnClose(Ukcp ukcp) { var peer = Global.NetManager.GetPeer(ukcp); OnClose(peer); Deregister(peer); }
public NetPeer GetPeer(Ukcp ukcp) { var id = ukcp.GetUniqueId(); channelPeers.TryGetValue(id, out var peer); return(peer); }
public void onConnected(Ukcp ukcp) { //OneThreadSynchronizationContext.Instance.Post((obj) => //{ // OnConnect?.Invoke((Ukcp)obj); //}, ukcp); OnConnect?.Invoke(ukcp); }
//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)); }
protected void KcpServer_OnConnect(Ukcp ukcp) { //新连接 NetManager.Instance.RegisterKcp(ukcp); //ulong hostId = Global.IdManager.GetHostId(channel.RemoteAddress.ToIPv4String()); Log.Info(string.Format("kcp_client_connected {0} {1}", Basic.GenID32FromName(ukcp.user().Channel.Id.AsLongText() + ukcp.user().Channel.LocalAddress.ToIPv4String() + ukcp.user().RemoteAddress.ToIPv4String()), ukcp.user().RemoteAddress.ToIPv4String())); }
public void handleException(Exception ex, Ukcp ukcp) { //OneThreadSynchronizationContext.Instance.Post((obj) => //{ // var objs = (object[])obj; // OnException?.Invoke((Ukcp)objs[0], (Exception)objs[1]); //}, new object[] { ukcp, ex}); OnException?.Invoke(ukcp, ex); }
public static NetPeer Create(uint connId, Ukcp kcpCh) { var obj = new NetPeer(); obj.ConnId = connId; obj.kcpChannel = kcpCh; obj.netType = NetworkType.KCP; return(obj); }
protected void KcpServer_OnConnect(Ukcp ukcp) { //新连接 NetManager.Instance.RegisterKcp(ukcp); //ulong hostId = Global.IdManager.GetHostId(channel.RemoteAddress.ToIPv4String()); Log.Info(string.Format("kcp_client_connected {0} {1}", ukcp.GetUniqueId(), ukcp.user().RemoteAddress.ToIPv4String())); }
//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 GetPeer(Ukcp ukcp) { var cid = ukcp.user().Channel.Id.AsLongText() + ukcp.user().Channel.LocalAddress.ToIPv4String() + ukcp.user().RemoteAddress.ToIPv4String(); var id = Basic.GenID32FromName(cid); channelPeers.TryGetValue(id, out var peer); return(peer); }
public void handleReceive(IByteBuffer byteBuf, Ukcp ukcp) { //OneThreadSynchronizationContext.Instance.Post((obj) => //{ // var objs = (object[])obj; //OnReceive?.Invoke(ukcp, byteBuf); // OnReceive?.Invoke((Ukcp)objs[1], (IByteBuffer)objs[0]); //}, new object[] { byteBuf.Retain(), ukcp }); OnReceive?.Invoke(ukcp, byteBuf); }
public KcpHostClient(ChannelConfig channelConfig, IPEndPoint remoteAddress) { if (client == null) { client = KcpClient.Instance; client.init(channelConfig); } this._ukcp = client.connect(remoteAddress, channelConfig, this); }
public void handleReceive(IByteBuffer byteBuf, Ukcp ukcp) { short curCount = byteBuf.GetShort(byteBuf.ReaderIndex); Console.WriteLine(Thread.CurrentThread.Name + " 收到消息 " + curCount); ukcp.write(byteBuf); if (curCount == -1) { ukcp.close(); } }
public void handleClose(Ukcp ukcp) { //OneThreadSynchronizationContext.Instance.Post((obj) => //{ // OnClose?.Invoke((Ukcp)obj); //}, ukcp); OnClose?.Invoke(ukcp); Log.Info(Snmp.snmp.ToString()); Snmp.snmp = new Snmp(); }
public KcpHostClient(ChannelConfig channelConfig, IPEndPoint remoteAddress) { if (client == null) { lock (lockObj) { if (client == null) { client = new KcpClient(); client.init(channelConfig); } } } this._ukcp = client.connect(remoteAddress, channelConfig, this); }
public void handleReceive(IByteBuffer byteBuf, Ukcp ukcp) { int curCount = byteBuf.ReadShort(); if (curCount == -1) { timer20.Elapsed += overHandler; } else { int idx = curCount - 1; long time = byteBuf.ReadInt(); if (rtts[idx] != -1) { Console.WriteLine("end"); } //log.info("rcv count {} {}", curCount, System.currentTimeMillis()); rtts[idx] = (int)(KcpUntils.currentMs() - startTime - time); Console.WriteLine("rtt : " + curCount + " " + rtts[idx]); } }
public static void start() { ChannelConfig channelConfig = new ChannelConfig(); channelConfig.initNodelay(true, 40, 2, true); channelConfig.Sndwnd = 512; channelConfig.Rcvwnd = 512; channelConfig.Mtu = 512; channelConfig.FecDataShardCount = 3; channelConfig.FecParityShardCount = 1; channelConfig.AckNoDelay = true; channelConfig.Crc32Check = true; channelConfig.Conv = 55; //channelConfig.setTimeoutMillis(10000); KcpClient kcpClient = new KcpClient(); kcpClient.init(channelConfig); KcpRttExampleClient kcpClientRttExample = new KcpRttExampleClient(); //kcpClient.connect(new InetSocketAddress("127.0.0.1",20003),channelConfig,kcpClientRttExample); EndPoint remoteAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 20003); _ukcp = kcpClient.connect(remoteAddress, channelConfig, kcpClientRttExample); try { kcpClientRttExample.init(); } catch (Exception e) { Console.WriteLine(e); throw; } }
public void DeregisterKcp(Ukcp ukcp) { var peer = GetPeer(ukcp); this.Deregister(peer); }
public void handleConnect(Ukcp ukcp) { }
private void KcpServer_OnException(Ukcp ukcp, Exception ex) { var peer = Global.NetManager.GetPeer(ukcp); OnException(peer, ex); }
public void handleClose(Ukcp ukcp) { Console.WriteLine(Snmp.snmp.ToString()); Snmp.snmp = new Snmp(); }
private void KcpServer_OnClose(Ukcp ukcp) { NetManager.Instance.DeregisterKcp(ukcp); }
private void KcpServer_OnReceive(Ukcp ukcp, IByteBuffer buffer) { var peer = Global.NetManager.GetPeer(ukcp); OnReceive(peer, buffer); }
private void KcpServer_OnReceive(Ukcp ukcp, IByteBuffer buffer) { var peer = NetManager.Instance.GetPeer(ukcp); OnReceiveBuffer(peer, buffer); }
private void KcpServer_OnException(Ukcp ukcp, Exception ex) { Log.Error(ex.ToString()); NetManager.Instance.DeregisterKcp(ukcp); }
public void onConnected(Ukcp ukcp) { }
public static ulong GetUniqueId(this Ukcp ukcp) { return(Basic.GenID64FromName(ukcp.user().Channel.Id.AsLongText() + ukcp.user().Channel.LocalAddress.ToIPv4String() + ukcp.user().RemoteAddress.ToIPv4String() + ukcp.getConv().ToString())); }
public void handleException(Exception ex, Ukcp ukcp) { Console.WriteLine(ex); }
public bool DeregisterKcp(Ukcp ukcp) { var peer = GetPeer(ukcp); return(this.Deregister(peer)); }
public void handleClose(Ukcp ukcp) { }