簡體   English   中英

C#tcpclient或udp套接字速率非常慢

[英]C# tcpclient or udp socket rate is VERY slow

而我的網絡支持MBS。 當我嘗試發送800個字節的1000個數據包時,大約需要24秒? 為什么要花這么長時間? 我也嘗試了UDP,但它也不是更好。 是否有任何要更改的參數? 有什么理由讓這個速度慢嗎?

我正在使用的代碼:

const string SERVER_IP = "10.10.10.34";
const int SERVER_PORT = 1234;

static void Main(string[] args)
{
    TcpClient client = new TcpClient();
    client.Connect(SERVER_IP, SERVER_PORT);       
    using (Stream stream = client.GetStream())
    {
        while (true)
        {

            byte[] data = new byte[800];
           DateTime start=DateTime.Now;
           for(int i=0;i<1000;i++)
            {

            stream.Write(data, 0, data.Length);
            }
            DateTime end=DateTime.Now;
            var duration = end-start;
        }
    }

    client.Close();
}

編輯注意:數據包的大小為800字節(而不是開頭的內容)

第一站... wireshark ,網絡上可以進行如此多的工作,最好查看一下跡線。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM