Help with single socket HTTP server on Spinneret Web Server
JohnR2010
Posts: 431
I'm having a problem getting reliable response to my new HTTP service i have written for my spinner project. I have based this off the examples mostly from Mike G's awesome multi socket server on http://spinneret-web-server.googlecode.com/svn/trunk/.
First let me start with saying from Firefox(6.0.1) everything works great. I can hit my server both locally and from the Internet and she is fast and renders HTML files, GIF images, and XML data with XSL formatting. I'm writing a single socket server to keep the footprint low both in RAM and available COGs, I need the space for other code.
The problem: Both Internet Explore and Safari on my iPad and iPhone have problems rendering the same code from the Internet. All browser works great when i hit the Spinner locally only see the problem through the Internet.
In troubleshooting this I discovered all browsers work both locally and from the Internet if I use Mike G's Multi socket server. It looks like Mike's code is servicing request in a second socket and it appears IE and Safari are sending multiple request at the same time that I cant handle with my single socket server. So I'm looking for any suggestions? Is there a way in the response header to tell the browser to only send request one at a time? Any other thoughts on what might be going on?
Thanks!
First let me start with saying from Firefox(6.0.1) everything works great. I can hit my server both locally and from the Internet and she is fast and renders HTML files, GIF images, and XML data with XSL formatting. I'm writing a single socket server to keep the footprint low both in RAM and available COGs, I need the space for other code.
The problem: Both Internet Explore and Safari on my iPad and iPhone have problems rendering the same code from the Internet. All browser works great when i hit the Spinner locally only see the problem through the Internet.
In troubleshooting this I discovered all browsers work both locally and from the Internet if I use Mike G's Multi socket server. It looks like Mike's code is servicing request in a second socket and it appears IE and Safari are sending multiple request at the same time that I cant handle with my single socket server. So I'm looking for any suggestions? Is there a way in the response header to tell the browser to only send request one at a time? Any other thoughts on what might be going on?
Thanks!
Comments
-Phil
https://secure.wikimedia.org/wikipedia/en/wiki/HTTP_pipelining#Implementation_in_web_browsers
https://secure.wikimedia.org/wikipedia/en/wiki/HTTP_persistent_connection
-Phil
One last note: If I understand Phil's thread properly some browsers will open several connections even more than 4. I guess a web page with a lot of small jpgs could overrun Mike's multi socket server?? I wish the W5100 would queue these request somehow. Hold them in a buffer until the code is ready to service them!
Does anyone know if we are going to have the same issue with the new WiFi module Parallax is working on? I also heard the Digi guys are coming out with a WiFi xBee?? ARRRGGGG I so wanted to base my projects on Spinner!!
That's right. Hence AJAX and JavaScript. I use AJAX and the DOM to update client pages. As Phil suggested, you can use JavaScript to request images after the page has loaded. Look at the source code on the home page of the Spinneret tutorial. There's a link that renders a Spinneret image. You could reuse the JavaScript HTTP GET in a setInterval command to load your images.
I remember reading on the Wireless forum that the WiFi will be one socket be can support multiple, not sure though.
Yep i saw your AJAX in your tutorial very sharp!! I have updated all my HTML to request data in an orderly fashion so far it is much more stable!
I'm down to one last problem:
Randomly (maybe once every 200 connections) my Spinn code gets stuck waiting for a socket to connect. I'm using "repeat while !W5100.SocketTCPestablished(0)" that just repeats itself waiting for the socket to enter the established state. On rare occasions It never leaves this state when a browser is trying to connect. Prior to issuing this command I make sure the socket successful gos through the close state, open state and has entered into the listen state by looking at the registers, so i know the socket is truly reporting it is reading for a connection. Mike, I notice you have a state machine that keeps an eye on the socket register, in doing this have you come across a time when a socket goes from listening state to some other state then established? I also notice your version of the W5100 is not the same as the latest version on the Google site. I wonder if i would be better off using your version of the W5100indirect? As a quick test I tried to use it but the methods i call have been renamed or are missing so I backed off. I wonder if I need to issue the reset command to the W5100 every 100 packets or so??
Thanks!!
There's a bare bones version in the Google repository similar to the original W5100 without the Request and Response objects. Some of the method names are changed, there is a memory lock, and the socket state is written to RAM.
You need a timer running in another process. Resting every 100 packets will not work.
Post your code.
I wasn't too serious about the reset <smile>. Probable as you were typing your suggestion I was making similar changes to what you suggest. Here is what I found out. I moved to a state-full view of the socket so I can see what is going on instead of blindly waiting for it to be established. I experience the problem the most when I connect to the Spinner from my iPhone over the Internet (AT&T 3G connection). Here are the socket states for a normal browser connection: [_SOCK_LISTEN],[ _SOCK_SYNRECV], and then [_SOCK_ESTAB]. A good connection via iPhone over 3g has the same basic conversation except it takes a much longer time from [_SOCK_SYNRECV] state to [_SOCK_ESTAB]. A bad connection that will hang my code goes from [ _SOCK_LISTEN],[ _SOCK_SYNRECV], and then to [_SOCK_CLOSED]. It never enters the [_SOCK_ESTAB] status and therefor my loop will hang because a socket will never go from closed to established. So I think I can easily fix this. Let me get back to my code its almost 5 here and I want this done before i quit!! Thanks!!!!
Update to my update: Everything is looking great now that I don't blindly just sit and wait for the socket to go from listen to established as several of the examples objects show on the Google code site. By calling the W5100.SocketTCPestablished(0) and just sitting and waiting for it to connect i was seeing my code hang. MikeG's code does it correctly you have to watch the state of the sockets and react appropriately! (Not that I'm qualified in any way to say who is right or wrong) I am extreamly tankful for all the examples and all the time everyone has spent!! I'm going to hit my spinner hard over the weekend and see if I can get it to fall over. If it doesn't I think I'm going to be able to incorporate this into our project!!