Padarn OpennetCF套接字连接已关闭

时间:2015-06-20 08:43:38

标签: compact-framework windows-ce padarn

我正在为我的项目评估Padarn,而我正在尝试实现一个非常简单的例子。我需要Padarn用于我的WIN CE 5.0或6.0 Web项目,我买了一个许可证 这是我的配置部分:

    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>

这是套接字连接检查器:

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

我正在检查套接字连接是否定期运行padarn(127.0.0.1:80)(每5秒),但有时padarn服务器已关闭!我无法连接到那个,当我检查套接字的端口时,它已断开连接,我必须重启Padarn

请帮帮我,这个配置有误吗?我的问题是什么?

1 个答案:

答案 0 :(得分:0)

我认为问题是TcpClients永远不会显式断开或关闭,所以每次调用IsPortOpen都会创建另一个TCP连接并保持打开状态。

在某些时候,Web服务器达到了它配置为处理的最大并发请求数(20?),或者客户端本身耗尽资源而无法创建更多连接。

事情最终将自己解决,因为Web服务器可能决定关闭非活动连接,或者连接客户端上的垃圾收集器可能会开始清理已超出范围的TcpClient实例,并沿途调用其Close / Dispose方法,关闭基础连接。

重新启动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;
        }
    }
}