// accept public KChannel(long id, uint localConn, uint remoteConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) { if (kChannels.ContainsKey(this.LocalConn)) { throw new Exception($"channel create error: {localConn} {remoteEndPoint} {this.ChannelType}"); } this.Id = id; this.ChannelType = ChannelType.Accept; Log.Info($"channel create: {this.Id} {localConn} {remoteConn} {remoteEndPoint} {this.ChannelType}"); this.Service = kService; this.LocalConn = localConn; this.RemoteConn = remoteConn; this.RemoteAddress = remoteEndPoint; this.socket = socket; this.kcp = Kcp.KcpCreate(this.RemoteConn, (IntPtr)localConn); kChannels.Add(this.LocalConn, this); this.lastRecvTime = kService.TimeNow; this.CreateTime = kService.TimeNow; this.InitKcp(); }
public void HandleConnnect() { // 如果连接上了就不用处理了 if (this.IsConnected) { return; } this.kcp = Kcp.KcpCreate(this.RemoteConn, IntPtr.Zero); this.InitKcp(); Log.Info($"channel connected: {this.Id} {this.LocalConn} {this.RemoteConn} {this.RemoteAddress}"); this.IsConnected = true; this.lastRecvTime = this.Service.TimeNow; while (true) { if (this.sendBuffer.Count <= 0) { break; } KcpWaitPacket buffer = this.sendBuffer.Dequeue(); this.KcpSend(buffer); } }
public void HandleConnnect() { // 如果连接上了就不用处理了 if (this.IsConnected) { return; } this.kcp = Kcp.KcpCreate(this.RemoteConn, new IntPtr(this.LocalConn)); this.InitKcp(); ulong localRmoteConn = ((ulong)this.RemoteConn << 32) | this.LocalConn; idLocalRemoteConn[this.Id] = localRmoteConn; // idLocalRemoteConn.TryAdd(this.Id, localRmoteConn); Log.Info($"channel connected: {this.Id} {this.LocalConn} {this.RemoteConn} {this.RemoteAddress}"); this.IsConnected = true; this.lastRecvTime = this.Service.TimeNow; while (true) { if (this.sendBuffer.Count <= 0) { break; } KcpWaitPacket buffer = this.sendBuffer.Dequeue(); this.KcpSend(buffer); } }
// accept public KChannel(long id, uint localConn, uint remoteConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) { this.Id = id; this.ChannelType = ChannelType.Accept; Log.Info($"channel create: {this.Id} {localConn} {remoteConn} {remoteEndPoint} {this.ChannelType}"); this.Service = kService; this.LocalConn = localConn; this.RemoteConn = remoteConn; this.RemoteAddress = remoteEndPoint; this.socket = socket; this.kcp = Kcp.KcpCreate(this.RemoteConn, IntPtr.Zero); this.InitKcp(); this.lastRecvTime = kService.TimeNow; this.CreateTime = kService.TimeNow; }
// accept public KChannel(uint localConn, uint remoteConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) : base(kService, ChannelType.Accept) { this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue); this.LocalConn = localConn; this.RemoteConn = remoteConn; this.remoteEndPoint = remoteEndPoint; this.socket = socket; this.kcp = Kcp.KcpCreate(this.RemoteConn, new IntPtr(this.LocalConn)); SetOutput(); Kcp.KcpNodelay(this.kcp, 1, 10, 1, 1); Kcp.KcpWndsize(this.kcp, 256, 256); Kcp.KcpSetmtu(this.kcp, 470); this.lastRecvTime = kService.TimeNow; this.createTime = kService.TimeNow; this.Accept(); }
public void HandleConnnect(uint remoteConn) { if (this.isConnected) { return; } this.RemoteConn = remoteConn; this.kcp = Kcp.KcpCreate(this.RemoteConn, new IntPtr(this.LocalConn)); SetOutput(); Kcp.KcpNodelay(this.kcp, 1, 10, 1, 1); Kcp.KcpWndsize(this.kcp, 256, 256); Kcp.KcpSetmtu(this.kcp, 470); this.isConnected = true; this.lastRecvTime = this.GetService().TimeNow; HandleSend(); }