-1
我正在編寫一個服務器,它在特定端口偵聽來自瀏覽器的請求,例如http://23.10.222.151:20000/mac=0080440EEE71
。我得到瀏覽器套接字,然後檢查它的請求,在這種情況下mac=2280440FFF23
。我看看有沒有什麼設備連接,如果不是我想顯示一個頁面,上面寫着「設備:{0}無法與服務器進行註冊,請稍候......」寫入C#套接字
TcpClient client = listener.AcceptTcpClient();
Console.WriteLine("Connection Accepted from " + client.Client.RemoteEndPoint);
NetworkStream ClientStream = client.GetStream();
if(!devDictionary.isDevicePresent(mac))
{
Thread onRequestThread = new Thread(new ParameterizedThreadStart(OnRequesstHandler));
onRequestThread.Start(new OnRequestHandlerObject(mac, ClientStream));
String notfound = String.Format("<html><body><h1>Device: {0} has NOT registered with the Server! Please wait...</h1></body></html>", mac);
byte[] response = encoder.GetBytes(notfound);
ClientStream.Write(response, 0, response.Length);
}
線程不斷檢查,如果該設備已連接。如果是,那麼它使用相同的ClientStream顯示它。但該頁面不會立即顯示。它保持循環,並在設備連接時快速連續顯示兩頁。如何立即顯示第一頁?
您是否嘗試過'ClientStream.Flush();'? – 2012-03-15 17:05:42
是的,我做到了。沒有工作... – batrulz 2012-03-15 17:08:24