也許只是觀看這部影片:http://screencast.com/t/OWE1OWVkO 正如你看到的,被啓動的連接之間的延遲(通過telnet或Firefox)和我的程序首先得到它的話。〜1秒的TcpListener待定()/ AcceptTcpClient()滯後
下面是用於連接
public IDLServer(System.Net.IPAddress addr,int port)
{
Listener = new TcpListener(addr, port);
Listener.Server.NoDelay = true;//I added this just for testing, it has no impact
Listener.Start();
ConnectionThread = new Thread(ConnectionListener);
ConnectionThread.Start();
}
private void ConnectionListener()
{
while (Running)
{
while (Listener.Pending() == false) { System.Threading.Thread.Sleep(1); }//this is the part with the lag
Console.WriteLine("Client available");//from this point on everything runs perfectly fast
TcpClient cl = Listener.AcceptTcpClient();
Thread proct = new Thread(new ParameterizedThreadStart(InstanceHandler));
proct.Start(cl);
}
}
等待(我有一些麻煩的代碼放到一個代碼塊)
我已經嘗試了幾個不同的東西,難道是我的代碼使用TcpClient/Listener而不是原始Socket對象?這不是我知道的強制性TCP開銷,並且我嘗試了在同一線程中運行所有內容等。
你最終發現問題了嗎? – vtortola 2014-02-18 11:04:55
好奇你是怎麼解決這個問題的,有同樣的問題 – ruslander 2015-08-05 23:50:52