Esempio n. 1
0
    static void RunBlast(Dictionary <String, String> args, Socket client, IInt32SequenceFactory sequenceFactory)
    {
        Console.WriteLine("Blasting TCP client...");

        IInt32Sequence sequence = sequenceFactory();

        int blockSize = 5112;

        long sequenceNumber = 0;

        byte[] block = new byte[blockSize];

        RateWatcher rate = new RateWatcher();

        for (; ;)
        {
            for (int i = 0; i < blockSize; i++)
            {
                int f = sequence.GetNext();
                block[i] = (byte)(f & 0xff);
                // Debug.WriteLine(String.Format("{0,3} -> 0x{1:x}", i, block[i]));
            }

            int bytesTransferred = client.Send(block, 0, blockSize, SocketFlags.None);
            if (bytesTransferred != blockSize)
            {
                Console.WriteLine("The send transferred fewer bytes than requested!");
                break;
            }

            sequenceNumber += blockSize;

            rate.AddBytes(blockSize);
        }
    }
Esempio n. 2
0
    static void RunGulp(Dictionary <String, String> args, Socket client, IInt32SequenceFactory sequenceFactory)
    {
        Console.WriteLine("Running Gulp.");

        IInt32Sequence sequence = sequenceFactory();

        long sequenceNumber = 0;

        int blockSize = 5112;

        byte[] block = new byte[blockSize];

        int ticksAtLastPrint = Environment.TickCount;

        RateWatcher rate = new RateWatcher();

        for (; ;)
        {
            int bytesRead = client.Receive(block);
            if (bytesRead == 0)
            {
                Console.WriteLine("The socket has closed.");
                return;
            }

            // Verify that the contents match the expected sequence.
            for (int i = 0; i < bytesRead; i++)
            {
                int  f        = sequence.GetNext();
                byte expected = (byte)(f & 0xff);

                if (block[i] != expected)
                {
                    Console.WriteLine("Received sequence does not match expected sequence!");
                    Console.WriteLine("At stream offset {0} (0x{0:x}), expected 0x{1:x}, received 0x{2:x}.",
                                      sequenceNumber,
                                      expected,
                                      block[i]);
                    return;
                }
            }

            sequenceNumber += bytesRead;

            rate.AddBytes(bytesRead);
        }
    }