// 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; }
// accept public KChannel(uint localConn, uint remoteConn, Socket socket, IPEndPoint remoteEndPoint, KService _kService) : base(_kService, ChannelType.Accept) { kService = _kService; 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(); this.RemoteAddress = remoteEndPoint; //if(!_kService.CheckKcpWaitsnd) // yuxj debug //{ // int dd= 0; //} }
//连接的处理 public void HandleConnnect(uint remoteConn) { if (this.isConnected) { return; } this.RemoteConn = remoteConn; this.kcp = Kcp.KcpCreate(this.RemoteConn, new IntPtr(this.LocalConn)); SetOutput(); //工作模式: //nodelay : 是否设置数据后合并发送 0不启用;1启用 //interval :协议内部工作的间隔时间,单位毫秒,比如 10ms或者 20ms //resend :快速重传模式,默认0关闭,可以设置2(2次ACK跨越将会直接重传) //nc :是否关闭流控,默认是0代表不关闭,1代表关闭 Kcp.KcpNodelay(this.kcp, 1, 10, 1, 1); //最大窗口:该调用将会设置协议的最大发送窗口和最大接收窗口大小 Kcp.KcpWndsize(this.kcp, 256, 256); //最大传输单元:纯算法协议并不负责探测 MTU,默认 mtu是1400字节,可以使用ikcp_setmtu来设置该值。该值将会影响数据包归并及分片时候的最大传输单元。 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.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue); this.LocalConn = localConn; this.RemoteConn = remoteConn; this.RemoteAddress = remoteEndPoint; //赋值一下端口 这是本人后期改的 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(); }