// accept public KChannel(uint localConn, uint remoteConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) : base(kService, ChannelType.Accept) { this.InstanceId = IdGenerater.GenerateId(); 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)); Kcp.KcpSetoutput( this.kcp, (bytes, len, k, user) => { KService.Output(bytes, len, user); return(len); } ); 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(); }
/// <summary> /// 处理2次握手连接 /// </summary> public void HandleConnnect(uint remoteConn) { if (this.isConnected) //发现已经是连接状态 不用处理 { return; } this.RemoteConn = remoteConn; this.kcp = Kcp.KcpCreate(this.RemoteConn, new IntPtr(this.LocalConn)); Kcp.KcpSetoutput( this.kcp, (bytes, len, k, user) => { KService.Output(bytes, len, user); return(len); } ); 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(); //握手连接后 把缓存的消息发过去 }
// accept public KChannel(uint localConn, uint remoteConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) : base(kService, ChannelType.Accept) { this.InstanceId = IdGenerater.GenerateId(); this.LocalConn = localConn; this.RemoteConn = remoteConn; this.remoteEndPoint = remoteEndPoint; this.socket = socket; this.kcp = Kcp.KcpCreate(this.RemoteConn, new IntPtr(this.LocalConn)); Kcp.KcpSetoutput( this.kcp, (bytes, len, k, user) => { KService.Output(bytes, len, user); return(len); } ); Kcp.KcpNodelay(this.kcp, 1, 10, 1, 1); Kcp.KcpWndsize(this.kcp, 256, 256); Kcp.KcpSetmtu(this.kcp, 470); this.isConnected = true; this.isRecvFirstKcpMessage = false; this.lastRecvTime = kService.TimeNow; this.CreateTime = kService.TimeNow; }
public void SetOutput() { #if ENABLE_IL2CPP Kcp.KcpSetoutput(this.kcp, KcpOutput); #else // 跟上一行一样写法,pc跟linux会出错 Kcp.KcpSetoutput(this.kcp, (buf, i, ptr, user) => KcpOutput(buf, i, ptr, user)); #endif }
public void SetOutput() { #if ENABLE_IL2CPP Kcp.KcpSetoutput(this.kcp, KcpOutput); #else // 跟上一行一样写法,pc跟linux会出错, 保存防止被GC kcpOutput = KcpOutput; Kcp.KcpSetoutput(this.kcp, kcpOutput); #endif }