public static void Init() { string myIp = "127.0.0.1"; ushort myProt = 40000; m_bDestory = false; InitBytePool(); m_Net = new KCP.Server.KCPServer(myIp, myProt); m_Net.NewClientSession += server_NewClientSession; m_Net.CloseClientSession += server_CloseClientSession; m_Net.RecvData += server_RecvData; for (int i = 1; i < 10000; i++) { m_Net.AddClientKey((uint)i, i); } PacketRegister.Init(null); m_Net.Start(); Log.print("启动监听{0}:{1}成功", myIp, myProt); while (true) { m_Net.Update(); } }
/// <summary> /// 仅仅处理KCP时钟,判断是否好久没有收到数据。 /// </summary> public void Update() { SmartUpdateKCP(KCPServer.iclock()); if (m_KCPServer.m_watch.Elapsed - m_LastRecvTimestamp > UdpLibConfig.MaxTimeNoData) { DisposeReason = ClientSessionDisposeReason.MaxTimeNoData; Dispose(); } }