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