// connect public KChannel(long id, uint localConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) { this.LocalConn = localConn; if (kChannels.ContainsKey(this.LocalConn)) { throw new Exception($"channel create error: {this.LocalConn} {remoteEndPoint} {this.ChannelType}"); } this.Id = id; this.ChannelType = ChannelType.Connect; Log.Info($"channel create: {this.Id} {this.LocalConn} {remoteEndPoint} {this.ChannelType}"); this.Service = kService; this.RemoteAddress = remoteEndPoint; this.socket = socket; this.kcp = Kcp.KcpCreate(this.RemoteConn, (IntPtr)this.LocalConn); kChannels.Add(this.LocalConn, this); this.lastRecvTime = kService.TimeNow; this.CreateTime = kService.TimeNow; this.Connect(); }
// connect public KChannel(uint localConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) : base(kService, ChannelType.Connect) { this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue); this.LocalConn = localConn; this.socket = socket; this.remoteEndPoint = remoteEndPoint; this.lastRecvTime = kService.TimeNow; this.createTime = kService.TimeNow; this.Connect(); }
// 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 static int KcpOutput(IntPtr bytes, int len, IntPtr kcp, IntPtr user) { KService.Output(bytes, len, user); return(len); }