コード例 #1
0
ファイル: Server.cs プロジェクト: rubarax2/socketperf-test-2
        void MemorySend(Socket client)
        {
            byte[] buffer = new byte[Constants.BUFFER_SIZE];
            (new Random()).NextBytes(buffer);

            uint totalLen = (uint)mData.SizeInMB * 1024 * 1024;

            int ini = Environment.TickCount;

            using (NetworkStream ns = new NetworkStream(client))
            {
                LengthSerializer.Serialize(ns, totalLen);

                uint toSent;
                uint totalSent = 0;
                do
                {
                    if ((totalLen - totalSent) < Constants.BUFFER_SIZE)
                    {
                        toSent = totalLen - totalSent;
                    }
                    else
                    {
                        toSent = Constants.BUFFER_SIZE;
                    }

                    ns.Write(buffer, 0, (int)toSent);

                    totalSent += toSent;
                }while (totalSent < totalLen);
            }

            LogPrinter.LogTime("memory: sent", totalLen, ini);
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: rubarax2/socketperf-test-2
        void ReadSend(Socket client)
        {
            uint length = (uint)new FileInfo(mData.FilePath).Length;

            byte[] buffer = new byte[Constants.BUFFER_SIZE];

            int ini = Environment.TickCount;

            using (NetworkStream ns = new NetworkStream(client))
            {
                LengthSerializer.Serialize(ns, length);

                using (FileStream fs = File.OpenRead(mData.FilePath))
                {
                    int read = fs.Read(buffer, 0, buffer.Length);
                    while (read > 0)
                    {
                        ns.Write(buffer, 0, read);
                        read = fs.Read(buffer, 0, buffer.Length);
                    }
                }
            }

            LogPrinter.LogTime("readsend: sent", length, ini);
        }
コード例 #3
0
ファイル: Server.cs プロジェクト: rubarax2/socketperf-test-2
        void TransmitFile(Socket client)
        {
            uint length = (uint)new FileInfo(mData.FilePath).Length;

            int ini = Environment.TickCount;

            using (NetworkStream ns = new NetworkStream(client))
            {
                byte[] lengthBytes = LengthSerializer.Serialize(length);

                // send the header
                client.SendFile(mData.FilePath, lengthBytes, null, TransmitFileOptions.UseKernelApc);
            }

            LogPrinter.LogTime("transmitfile: sent", length, ini);
        }