1

I'm evaluating Padarn for my project and I'm trying to implement a very simple example. I need Padarn for my WIN CE 5.0 or 6.0 web project and I bought a license This is my configuration part :

    static void Main(string[] args)
    {

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

And this is my Render Function:

  protected override void Render(HtmlTextWriter writer)
    {            

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

    }

And this is my config file :

 <?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>

And this is socket connection checker :

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

I'm checking socket connection that padarn is run on ( 127.0.0.1 : 80 ) periodically (every 5 seconds) but sometimes padarn server is down !!! and I can't connect to that ,when I check the socket's port , its disconnected and I have to restart Padarn

please help me , Is this configuration wrong ? What's my problem ?

Taha Arian
  • 21
  • 3
  • What you have looks correct. What is this "socket connection" that you're using? Are you properly closing that socket? It's possible that your networking stack itself has a load of open sockets and it just has no more to give you, depending on how you wrote that app. We've got Padarn on machines that are pushing data out every second and running for weeks with no issues. – ctacke Jun 20 '15 at 17:05
  • @ctacke It's a kind of TcpClient that used for checking padarn ip/port ,according to IsPortOpen() function. I had this problem before adding this function too.Do you think that related to closing the socket checker? The most probable scenario that happened is rebooting win CE and the Device. Thanks for your attention – Taha Arian Jun 21 '15 at 07:48

1 Answers1

0

The problem I believe is that the TcpClients are never explicitly disconnected or closed, so with each call to IsPortOpen another TCP connection will be created and left open.

At some point the web server reaches the maximum number of concurrent requests it is configured to handle (20?), or the client itself runs out of resources and is unable to create more connections.

Things eventually sort themselves out as the web server may decide to close inactive connections, or the garbage collector on the connecting client may start cleaning up TcpClient instances that have gone out of scope, invoking their Close/Dispose methods along the way and closing the underlying connections.

The fact that restarting Padarn solves the issue shows that it is probably the web server that runs out of resources first (or starts rejecting connections when its maximum number has been reached).

Try explicitly closing each connection:

private static bool IsPortOpen()
{
    using(TcpClient tcpClient = new TcpClient())
    {
        try
        {
            tcpClient.Connect("127.0.0.1", 80);
            return true;
        }
        catch(Exception)
        {
            return false;
        }
    }
}
Carsten Hansen
  • 1,508
  • 2
  • 21
  • 27