// SetupKcp creates and configures a new KCP instance. // => useful to start from a fresh state every time the client connects // => NoDelay, interval, wnd size are the most important configurations. // let's force require the parameters so we don't forget it anywhere. protected void SetupKcp(bool noDelay, uint interval = Kcp.INTERVAL, int fastResend = 0, bool congestionWindow = true, uint sendWindowSize = Kcp.WND_SND, uint receiveWindowSize = Kcp.WND_RCV, int timeout = DEFAULT_TIMEOUT) { // set up kcp over reliable channel (that's what kcp is for) kcp = new Kcp(0, RawSendReliable); // set nodelay. // note that kcp uses 'nocwnd' internally so we negate the parameter kcp.SetNoDelay(noDelay ? 1u : 0u, interval, fastResend, !congestionWindow); kcp.SetWindowSize(sendWindowSize, receiveWindowSize); // IMPORTANT: high level needs to add 1 channel byte to each raw // message. so while Kcp.MTU_DEF is perfect, we actually need to // tell kcp to use MTU-1 so we can still put the header into the // message afterwards. kcp.SetMtu(Kcp.MTU_DEF - CHANNEL_HEADER_SIZE); // create message buffers AFTER window size is set // see comments on buffer definition for the "+1" part kcpMessageBuffer = new byte[1 + ReliableMaxMessageSize(receiveWindowSize)]; kcpSendBuffer = new byte[1 + ReliableMaxMessageSize(receiveWindowSize)]; this.timeout = timeout; state = KcpState.Connected; refTime.Start(); }
protected void SetupKcp() { kcp = new Kcp(0, RawSend); kcp.SetNoDelay(); open = true; Tick(); }
// NoDelay, interval, window size are the most important configurations. // let's force require the parameters so we don't forget it anywhere. protected void SetupKcp(bool noDelay, uint interval = Kcp.INTERVAL, int fastResend = 0, bool congestionWindow = true, uint sendWindowSize = Kcp.WND_SND, uint receiveWindowSize = Kcp.WND_RCV) { kcp = new Kcp(0, RawSend); // set nodelay. // note that kcp uses 'nocwnd' internally so we negate the parameter kcp.SetNoDelay(noDelay ? 1u : 0u, interval, fastResend, !congestionWindow); kcp.SetWindowSize(sendWindowSize, receiveWindowSize); refTime.Start(); state = KcpState.Connected; Tick(); }
// NoDelay, interval, window size are the most important configurations. // let's force require the parameters so we don't forget it anywhere. protected void SetupKcp(bool noDelay, uint interval = Kcp.INTERVAL, int fastResend = 0, bool congestionWindow = true, uint sendWindowSize = Kcp.WND_SND, uint receiveWindowSize = Kcp.WND_RCV) { // set up kcp over reliable channel (that's what kcp is for) kcp = new Kcp(0, RawSendReliable); // set nodelay. // note that kcp uses 'nocwnd' internally so we negate the parameter kcp.SetNoDelay(noDelay ? 1u : 0u, interval, fastResend, !congestionWindow); kcp.SetWindowSize(sendWindowSize, receiveWindowSize); // IMPORTANT: high level needs to add 1 channel byte to each raw // message. so while Kcp.MTU_DEF is perfect, we actually need to // tell kcp to use MTU-1 so we can still put the header into the // message afterwards. kcp.SetMtu(Kcp.MTU_DEF - CHANNEL_HEADER_SIZE); state = KcpState.Connected; refTime.Start(); }