Example #1
0
        void RawInput(EndPoint endpoint, byte[] data, int msgLength)
        {
            // is this a new connection?
            if (!connectedClients.TryGetValue(endpoint as IPEndPoint, out KcpServerConnection connection))
            {
                // very first message from this endpoint.
                // lets validate it before we start KCP
                if (!Validate(data, msgLength))
                {
                    return;
                }

                int channel = KcpConnection.GetChannel(data);

                // handshake must start in reliable channel
                if (channel != Channel.Reliable)
                {
                    return;
                }

                // fire a separate task for handshake
                // that way if the client does not cooperate
                // we can continue with other clients
                ServerHandshake(endpoint, data, msgLength).Forget();
            }
            else
            {
                connection.RawInput(data, msgLength);
            }
        }
Example #2
0
 // use same Kcp configuration on server and client
 void ConfigureKcpConnection(KcpConnection connection)
 {
     // NoDelay=false doesn't scale past ~1000 monsters. let's force enable it.
     connection.kcp.SetNoDelay(true, 10, 2, true);
     // PUMP those numbers up.
     // this works for 4k:
     //connection.kcp.SetWindowSize(128, 128);
     // this works for 10k:
     //connection.kcp.SetWindowSize(512, 512);
     // this works for 20k:
     connection.kcp.SetWindowSize(8192, 8192);
 }