HttpRequestHandler easts Sockets

I tried the nice “WEBSERVER EXTENSION FOR FEZ COBRA” for Fez Cobra from the Code section.

This example uses the HttpRequestHandler but it seems that this easts Sockets, too.
After 128 times refresh of a page the server stoops working

I have added (according to other forum threads):
context = listener.GetContext();


Earlier I tried this web server example (with sockets):

Her I added:
newSock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true);
to solve a similar problem with eating Sockets - this free sockets (do not linger)):

But, this I cannot do this with the HttpRequestHandler.

So, I think that both WebServer examples f lags from this Socket problem.
What to do?

See this please

Hello Niels,

I have been working myself with the httplistenerclass for weeks now. I am not seeing the eating problem on the wiz5100 stack (not cobra), and happily since on this stack we are onlylimited to 4 simultaneous sockets !

The benefits from this class are great, however many times I feel like going back to making a web server with regular server sockets for professionnal application (when the “it hardly never crashes” is not enough !). I am using the wiz5100 version of the class and I am meeting different but similar problems (plus : the getcontext is blocking, so difficult to stop if you need it: you may abort the thread holding it, but then you get memory leaks, etc). The class is not very stable on the long term. I “solve” the problem my reseting the ip stack on a regular basis,or depending on the error abort the listener and starting it again, but that does not always work.

The “WEBSERVER EXTENSION FOR FEZ COBRA” class by Wouter is really great, and hoppefuly he will be able to help you with it, as I don’t own a Cobra and httplistener behavior is different (better) on this board. :wink:

Are you getting an exception on the 129th time you are loading the page ?

I have mixed the “WEBSERVER EXTENSION FOR FEZ COBRA” and “A Basic TCP server” (the DHCP part - and the HTML page refresh line

“<META http-equiv=“REFRESH” content=“1;URL=” + sourceIP + “”>”.

This works fine for the first 128 browser refresh - then the weber server stops responding.

How do you “reseting the ip stack on a regular basis”?
I can just count how many time I ask for the context, listener.GetContext();

Does the wiz5100 work directly on the FEZ Cobra?

I think the link I gave you has the answer. Please try it first

That is the one I got the “disable linger” code from.

But how to do that with HttpRequestHandler?

I need access to the Socket to add

Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, -2);

To stop the Linger - which seems to cause the problem.

Good point. I am not sure how. In worst case you can take the HTTP code from the PK and use it with modifications

After som investigations with .Net Reflector on the HttpListener etc. it is clear that these classes hides the Socket class - and this Socket is not access able.

Next, on Socket.Close() the Socket is not released because of the Linger - and it is not possible to add

Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, -2);

So the Socket is released from the Stack.

Is there another way to control the Linger?

(Else I think that these classes of the NETMF is useless - because they die after 128 times of user access, which is the maximum number of Sockerts allowed)

Hmm, I had my Cobra running the webserver class for days, with several requests per day. But indeed I had to reset the board when I couldn’t access the webpages anymore.

Didn’t investigated this further for now, but it might just be the issue you described.