public override bool Init() { IdGenerater.AppId = 10; m_KService = new KService(NetHelper.ToIPEndPoint("127.0.0.1", 2000), Accept); m_KService.DisConnectedCallback += Service_DisConnectCallback; Log.Debug("TestKcpMd"); return(base.Init()); }
private void InitKcpServer() { this.packager = new CShaperPackager(); this.kServer = new KService(new IPEndPoint(IPAddress.Any, 3900)) { OnReadCallback = this.OnServiceReadCallback, OnErrorCallback = this.OnServiceErrorCallback }; }
void Start() { m_KService = new KService(); m_KService.DisConnectedCallback += KService_DisConnectCallback; /* * m_kChannel = (KChannel)m_KService.ConnectChannel(NetHelper.ToIPEndPoint("127.0.0.1", 2000)); * Log.Debug($"{TimeHelper.ClientNowSeconds()}"); */ }
private ActionResult List <TEntity, KService>() where TEntity : class where KService : ISimpleService <TEntity>, new() { var service = new KService(); var vModel = new SimpleListVModel <TEntity>(); vModel.Entities = service.GetEntities(); return(View(vModel)); }
private static async void TryConnectKService() { var xService = new KService(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 0)); var channel = await xService.ConnectChannelAsync(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234)); if (channel != null) { Log.Info($"TryConnectKService Success: channelId={channel.Id}, thread={System.Threading.Thread.CurrentThread.ManagedThreadId}, ipEndPoint={((KChannel)channel).ClientSocket.Client.LocalEndPoint.ToString()}"); for (int i = 0; i < 5; i++) { var words = $"data={i}"; var data = System.Text.Encoding.UTF8.GetBytes(words); channel.Send(data); Log.Info($"ConnectChannelAsync.Send: channelId={channel.Id}, thread={System.Threading.Thread.CurrentThread.ManagedThreadId}, {words}"); } } else { Log.Error("TryConnectKService Error!!!"); } }
private static async ETTask CheckAsync(RouterCheckComponent self) { Session session = self.GetParent <Session>(); long instanceId = self.InstanceId; while (true) { if (self.InstanceId != instanceId) { return; } await TimerComponent.Instance.WaitAsync(1000); if (self.InstanceId != instanceId) { return; } long time = TimeHelper.ClientFrameTime(); if (time - session.LastRecvTime < 7 * 1000) { continue; } try { long sessionId = session.Id; uint localConn = 0; uint remoteConn = 0; KService service = session.AService as KService; KChannel kChannel = service.Get(sessionId); if (kChannel == null) { Log.Warning($"not found remoteConn: {sessionId}"); continue; } localConn = kChannel.LocalConn; remoteConn = kChannel.RemoteConn; IPEndPoint realAddress = self.GetParent <Session>().RemoteAddress; Log.Info($"get recvLocalConn start: {self.ClientScene().Id} {realAddress} {localConn} {remoteConn}"); (uint recvLocalConn, IPEndPoint routerAddress) = await RouterHelper.GetRouterAddress(self.ClientScene(), realAddress, localConn, remoteConn); if (recvLocalConn == 0) { Log.Error($"get recvLocalConn fail: {self.ClientScene().Id} {routerAddress} {realAddress} {localConn} {remoteConn}"); continue; } Log.Info($"get recvLocalConn ok: {self.ClientScene().Id} {routerAddress} {realAddress} {recvLocalConn} {localConn} {remoteConn}"); session.LastRecvTime = TimeHelper.ClientNow(); ((KService)session.AService).ChangeAddress(sessionId, routerAddress); } catch (Exception e) { Log.Error(e); } } }