// 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(); }