2015-06-20 14 views
1

我爲我的項目評估帕達恩,我想實現一個非常簡單的例子。我需要帕達恩我的WIN CE 5.0或6.0的Web項目,我買一個牌照 這是我的配置部分:帕達恩OpennetCF套接字連接被關閉

static void Main(string[] args) 
    { 

      m_padarnServer = new WebServer(); 
      m_padarnServer.Start(); 
    } 

這是我的渲染功能:

protected override void Render(HtmlTextWriter writer) 
    {    

      if (Response.IsClientConnected) 
      { 
       Response.Write("OK"); 
       Response.Flush(); 
       writer.Flush(); 
      } 

    } 

這是我的配置文件:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
<configSections> 
<section name="WebServer" type="OpenNETCF.Web.Configuration.ServerConfigurationHandler, OpenNETCF.Web" /> 
<section name ="httpRuntime" type ="OpenNETCF.Web.Configuration.HttpRuntimeConfigurationHandler, OpenNETCF.Web"/> 
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>   
</configSections> 
    <WebServer 
    DefaultPort="80" 
    MaxConnections="20" 
    DocumentRoot="\nandFlash\Inetpub\" 
    Logging="true" 
    LogFolder="\Temp\Logs" 
    LogExtensions="aspx;html;htm;zip" 
    UseSsl="false" 
    > 
    <DefaultDocuments> 
    <Document>default.aspx</Document> 
    </DefaultDocuments> 
    <VirtualDirectories /> 
    <Cookies /> 
    <Caching /> 
    </WebServer> 

<httpRuntime 
    maxRequestLength="3000000" 
    requestLengthDiskThreshold="256" 
    /> 
<requestLimits maxAllowedContentLength="2097151000"/> 

</configuration> 

這是socket連接檢查:

private static bool IsPortOpen() 
    { 
     TcpClient tcpClient = new TcpClient();    
     try 
     { 
      tcpClient.Connect("127.0.0.1", 80);     
      return true; 
     } 
     catch (Exception) 
     { 
      return false; 
     } 
    } 

我認爲帕達恩上(127.0.0.1:80)運行檢查插座連接定期(每5秒),但有時帕達恩服務器已停機!我無法連接到的是,當我檢查插座的港口,其斷開,我必須重新啓動帕達恩

請幫助我,這是配置錯了嗎?我的問題是什麼?

+0

你有什麼看起來是正確的。你使用的是什麼「套接字連接」?你是否正確關閉那個插座?有可能您的網絡堆棧本身有一些開放的套接字,並且根本無法提供給您,這取決於您編寫該應用程序的方式。我們已經將Padarn應用在每秒鐘都在推送數據並且運行數週而沒有問題的機器上。 – ctacke

+0

@ctacke根據IsPortOpen()函數,它是一種用於檢查padarn ip/port的TcpClient。在添加此功能之前,我遇到了這個問題。您認爲這與關閉套接字檢查器有關嗎?發生的最可能的情況是重新啓動贏得CE和設備。感謝您的關注 –

回答

0

我相信問題是,TcpClients不會顯式地斷開或每次調用IsPortOpen將被創建並保持打開另一個TCP連接關閉,所以。

在某一點上的Web服務器達到它被配置爲處理的併發請求的最大數量(20?),或在客戶端本身運行資源不足,無法創造更多的連接。

事情最終自己解決問題作爲Web服務器可以決定關閉不活動的連接,或者連接客戶端上的垃圾收集器可以開始清理已超出範圍TcpClient的實例,調用它們的關閉/處置沿途方法並關閉底層連接。

重新啓動Padarn解決問題的事實表明,它可能是Web服務器首先耗盡資源(或者在達到最大數量時開始拒絕連接)。

儘量明確關閉每個連接:

private static bool IsPortOpen() 
{ 
    using(TcpClient tcpClient = new TcpClient()) 
    { 
     try 
     { 
      tcpClient.Connect("127.0.0.1", 80); 
      return true; 
     } 
     catch(Exception) 
     { 
      return false; 
     } 
    } 
}