Shop OBEX P1 Docs P2 Docs Learn Events
Help with single socket HTTP server on Spinneret Web Server — Parallax Forums

Help with single socket HTTP server on Spinneret Web Server

JohnR2010JohnR2010 Posts: 431
edited 2011-09-02 15:14 in Propeller 1
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!

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-09-01 10:14
    See this thread for how I addressed the problem using Javascript:

    -Phil
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-09-01 10:23
    I tried the "persistent connection" thing, but to no avail. According to the Wiki article, only Opera can do pipelining. Unfortunately, there seems to be nothing that the server can do to force every browser to use a single socket -- except to make additional content, such as images, unlinkable until the current content has completely loaded. That's what my Javascript code does.

    -Phil
  • JohnR2010JohnR2010 Posts: 431
    edited 2011-09-01 12:16
    Thanks guys! After following Phil's thread you guys have already been down this road (and it looks like it was a dead end). I will stop beating my head against the desk. I will either pull out the graphics in my HTML or use Phil's trick of loading them one at a time with JScript (what a pain! sorry just not happy with all this lots of late hours!!)

    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!!
  • Mike GMike G Posts: 2,702
    edited 2011-09-01 13:47
    JohnR2010 wrote:
    I wish the W5100 would queue these request somehow. Hold them in a buffer until the code is ready to service them!
    The W5100 does buffer the data... in 4 socket buffers.
    JohnR2010 wrote:
    I guess a web page with a lot of small jpgs could overrun Mike's multi socket server??
    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.
    JohnR2010 wrote:
    Does anyone know if we are going to have the same issue with the new WiFi module Parallax is working on?
    I remember reading on the Wireless forum that the WiFi will be one socket be can support multiple, not sure though.
  • JohnR2010JohnR2010 Posts: 431
    edited 2011-09-02 13:35
    Mike G wrote: »
    The W5100 does buffer the data... in 4 socket buffers.


    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!!
  • Mike GMike G Posts: 2,702
    edited 2011-09-02 13:56
    JohnR2010 wrote:
    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.
    That's one of the reasons I created the multi-socket driver! I wanted a separate process to handle the sockets.

    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.
    JohnR2010 wrote:
    I wonder if I need to issue the reset command to the W5100 every 100 packets or so
    You need a timer running in another process. Resting every 100 packets will not work.

    Post your code.
  • JohnR2010JohnR2010 Posts: 431
    edited 2011-09-02 14:27
    Mike G wrote: »
    That's one of the reasons I created the multi-socket driver! I wanted a separate process to handle the sockets.

    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!!!!
  • JohnR2010JohnR2010 Posts: 431
    edited 2011-09-02 15:14
    JohnR2010 wrote: »
    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!!
Sign In or Register to comment.