Shop OBEX P1 Docs P2 Docs Learn Events
Hosting a website - Page 2 — Parallax Forums

Hosting a website

2»

Comments

  • linzycumbialinzycumbia Posts: 27
    edited 2011-02-06 12:30
    Port 80 is the default HTTP port. What I was asking is how the browser can find the server if it is running through a port (5000) that is not default. Normally you would have to enter the address (71.63.4.228) followed by the port number (:5000) so you would have this as the address (71.63.4.228:5000). My router is set up to forward public port 5000 to private port 80. The spinneret is set up as follows
    'Start the W5100 driver
      W5100.StartINDIRECT(_WIZ_data0, _WIZ_addr0, _WIZ_addr1, _WIZ_cs, _WIZ_rd, _WIZ_wr,  _WIZ_rst, _WIZ_sen)
    
      MAC[0] := $00
      MAC[1] := $08
      MAC[2] := $DC
      MAC[3] := $16
      MAC[4] := $F0
      MAC[5] := $10
    
      'Subnet address to be assigned to W5100
      Subnet[0] := 255
      Subnet[1] := 255
      Subnet[2] := 255
      Subnet[3] := 0
    
      'IP address to be assigned to W5100
      IP[0] := 10
      IP[1] := 0
      IP[2] := 1
      IP[3] := 2
    
      'Gateway address of the system network
      Gateway[0] := 10
      Gateway[1] := 0
      Gateway[2] := 1
      Gateway[3] := 1
      'Local socket
      localSocket := 80 
       
      'Destination IP address - MUST BE SET TO THE SERVER TO CONNECT TO
    
      destIP[0] := 0
      destIP[1] := 0
      destIP[2] := 0
      destIP[3] := 0
      destSocket := 80
    
    

    My IP address is 71.63.4.228 or http://www.blueridgemountainresources.com sometimes everything loads sometimes nothing loads. If the page loads with a white background refresh it. On the photos page the photos never load. Also the server gets hung if you refresh the page before it finishes loading.
  • linzycumbialinzycumbia Posts: 27
    edited 2011-02-06 12:33
    Oh and the files that get hung are images like on the photos page and video like the one on this link http://www.blueridgemountainresources.com/media/hslides/computer.mp4 This video is supposed to go in the player on the homepage but I removed it so the server would not hang.
  • Mike GMike G Posts: 2,702
    edited 2011-02-06 13:02
    You have a lot of IO going on. You can take a look at the log.txt file to get an idea what's of happening. Should be on the root if you loaded HttpServer.spin found on this forum thread.

    I'm sure the Spinneret can serve up your site, it's just a matter of figuring out the problem and adjusting the code base.
  • linzycumbialinzycumbia Posts: 27
    edited 2011-02-06 14:14
    I tried loading the code you had put on this thread but the server would not work at all. Can you tell me which files are required to use your new code?
  • Mike GMike G Posts: 2,702
    edited 2011-02-06 14:31
    I only added the two files that were updated to the zip archive. All the supporting files stayed the same and were not part of the zip archive. Be aware that the code is a bit raw. It still has a lot of debugging statements for a terminal application.

    What does this mean?
    I tried loading the code you had put on this thread but the server would not work at all.

    Did you receive an error? If so what was the error? Try adding a blank log.txt file to the root.
  • linzycumbialinzycumbia Posts: 27
    edited 2011-02-10 12:26
    When the server rebooted after loading the code the red light stayed lit and when I went to the web address of the spinneret the site would not load. Can you post the spin files you use so I can compare them to the ones I am using and try to find a solution.
  • Mike GMike G Posts: 2,702
    edited 2011-02-10 15:27
    Try adding an empty log.txt and favicon.ico to the root of the SD card. I did not check if log.txt exists before trying to open the file. I simply added the file so I could do some quick and dirty logging.

    What changes have you made?

    Source code:
    http://www.agaverobotics.com/spinneret/source/
  • linzycumbialinzycumbia Posts: 27
    edited 2011-02-25 13:42
    I tried the code you posted above but the server would not work. When the server restarted after loading the code it came up with status code 14 in the terminal. I don't know what this means but I still can't get your code to work with the server. Any suggestions? Thanks
  • Mike GMike G Posts: 2,702
    edited 2011-02-25 17:20
    after loading the code it came up with status code 14 in the terminal. I don't know what this means but
    According to the openly published WIZ5100 manual a status code of $14...
    It is shown in case that LISTEN commands are given to
    Sn_CR at the SOCK_INIT status. The related socket will
    operate as TCP Server mode, and become ESTABLISHED status
    if connection request is normally received.

    Which means that the web server is waiting for a request.
    I still can't get your code to work with the server. Any suggestions?

    I admit that my code is beta at best and was more of a "getting my feet wet" exercise. There is a bug in my GET and POST methods other than that I can generate dynamic content and linked files no problem. I don't know what happening on your end as the problem description is not very detailed. I 'd have to get your HTML files and drop them on my spinneret to see what you're talking about.

    I'm in the middle of a rewrite. I'm not sure how long it will take. Spinneret time is directly proportional to my wife's tolerance. My advice... wait until I post the new code, grab other code, or roll your own.
  • linzycumbialinzycumbia Posts: 27
    edited 2011-02-26 11:06
    I don't understand why the spinneret has to have the WriteResponseHeader section. Why does the spinneret have to know what type of file it is serving up? In other words when someone connects to the website why can't the spinneret just sent the files to the client? When someone connected to a web server I thought it just sent the requested files to them.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-02-26 11:23
    When someone connected to a web server I thought it just sent the requested files to them.
    No, web transactions don't work that way. There is behind-the-scenes handshaking going on (on top of TCP) called the Hypertext Transfer Protocol (HTTP), which client requests and server responses must adhere to. The Spinneret's W5100 chip handles the TCP stuff, but it is up to the Propeller program to take care of HTTP requirements.

    All web requests and responses require an HTTP header. (The nice thing about HTTP is that's it's entirely in human-readable ASCII form.) In the case of server responses, these tell the client what kind of data it's receiving, be it a webpage, an image, or a file. For example, the following would tell the client that the data make up a JPEG image:
    Content-type: image/jpeg

    In the best of circumstances, this "mime-type" supercedes any suffixes that may be appended to the file or page name. The header can also include information about whether or not the data should be cached (and, if so, for how long), whether it's sent encrypted or not, when it was last modified, and many other things.

    The end of the header is signaled by one blank line, after which the actual content can begin.

    -Phil
  • linzycumbialinzycumbia Posts: 27
    edited 2011-02-26 11:25
    On a normal web server running Mac OS X on Linux is the information like mime types held in the .htaccess file? Also how can normal web servers send any type of file to a client?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-02-26 11:35
    No, .htaccess is used to restrict who can access the resource folder in which the files exist.

    All webservers ("normal" or otherwise) can send any type of file by prepending the necessary HTTP header that tells the client what kind of file it is.

    -Phil
  • linzycumbialinzycumbia Posts: 27
    edited 2011-02-26 11:42
    So if I wanted the spinneret to be able to send any type of file, I could add all of the mime content types to the WriteResponseHeader section? (At least all of the mime content types that exist)
  • Mike GMike G Posts: 2,702
    edited 2011-02-26 11:51
    The Spinneret will serve up any file. The content-type tells the client (your browser) hey here comes an image or a web page.

    This should help you to understand the HTTP protocol a little better.
    http://www.w3.org/Protocols/rfc2616/rfc2616.html
  • linzycumbialinzycumbia Posts: 27
    edited 2011-02-26 11:51
    I have noticed a bug in the spin code but I can't find a solution. When I access a page of the website the page loads but the spinneret gets stuck in a loop where is says
    ****************************
    SocketTCPestablished
    packetSize: 0
    ****************************
    ****************************
    SocketTCPestablished
    packetSize: 0
    ****************************
    ****************************
    SocketTCPestablished
    packetSize: 0
    ****************************
    
    over and over again more than 100 times before it finally stops and says
    ****************************
    SocketTCPestablished
    packetSize: 0
    ****************************
    ResetSocket
    Timeout Alert:
    ****************************
    SocketTCPestablished
    packetSize: 0
    ****************************
    Timer set: 498274904
    ****************************
    SocketTCPestablished
    packetSize: 0
    ****************************
    ResetSocket
    Timeout Alert:
    ****************************
    
    What might be causing this to happen? While the spinneret is doing this it is unresponsive.
  • Mike GMike G Posts: 2,702
    edited 2011-02-26 16:39
    I have noticed a bug in the spin code but I can't find a solution.
    How do you know this is a bug? What steps have you taken to determine this is a bug?
    When I access a page of the website the page loads but the spinneret gets stuck in a loop where is says
    What page is being requested? Can you post the HTML? What's in the log.txt file?
    What might be causing this to happen?
    A request(s) is made, but no data is in the rx buffer.

    How did you get the code working? Are you using the latest code?
  • linzycumbialinzycumbia Posts: 27
    edited 2011-02-26 17:30
    I went back to the code I was using a while ago. The old code does not have a log.txt and the logging never worked before so I just did not implement into my old code. I don't know for sure if it is a bug but I guessed it was because it happens any time I load a page of the website that has not been loaded before.

    Also the server does not always serve up all of the requested files/ files required for the page. these files include images and CSS files. Some times it serves up all of the files. Some times it doesn't. I have looked for a solution but have not found a problem.
  • Mike GMike G Posts: 2,702
    edited 2011-02-26 19:38
    This is my most recent code base.
    http://www.agaverobotics.com/spinneret/source/
  • linzycumbialinzycumbia Posts: 27
    edited 2011-02-27 07:55
    Mike G wrote: »
    This is my most recent code base.
    http://www.agaverobotics.com/spinneret/source/

    Awesome! This does not include the HTTPServer.spin. Where is the most recent HTTPServer.spin
  • Mike GMike G Posts: 2,702
    edited 2011-02-27 11:57
    Added HTTPServer.spin to the zip.
  • linzycumbialinzycumbia Posts: 27
    edited 2011-03-10 14:33
    I tried your new code. I found that the spinneret only loads the page once and then stops responding. It then must be reset. I looked in the log and it appears that the socket never gets reset after the first page load. Any ideas?
  • Mike GMike G Posts: 2,702
    edited 2011-03-10 17:01
    I'm afraid that the current code base is not going to work for your needs. Every resource request (scr="") in the html can cause the browser to open a new connection on the server as the page is rendered on the client. Phil identified the multiple connections issue and came up with a JavaScript solution that loads images after the HTML page loads. I'm not sure Phil's fix will be a convenient or workable option for your application.

    I beleive your application will require all 4 WIZ5100 sockets and there's no guarantee that it will work. Then again, this is the latest information. The situation could change with more development.
    Any ideas?

    You could help with development?
  • linzycumbialinzycumbia Posts: 27
    edited 2011-03-22 19:02
    How would one go about enabling all 4 sockets? Yes I could help with dev.
  • kuismakuisma Posts: 134
    edited 2011-03-23 00:14
    How would one go about enabling all 4 sockets?

    This would mitigate the effects of the problem, but not solve the problem itself.
  • ChrisCantrellChrisCantrell Posts: 25
    edited 2011-06-20 18:33
    Your code is working great for me. Thank you so much for all the hard work and for sharing with the community.
  • computer guycomputer guy Posts: 1,113
    edited 2011-07-04 22:17
    I just downloaded the code provided by "Mike G", just a note: Javascript has a mime type of "application/javascript".
    I noticed that in the HTTPServer.spin file it has "text/javascript", this will cause problems for some borwsers as they will refuse to parse the javascript files.

    I suggest changing this.

    I am working on a revised "WriteResponseHeader" function, but don't have a Spinneret.
    Could someone please test it and let me know how it goes (once I post it).
  • computer guycomputer guy Posts: 1,113
    edited 2011-07-04 23:07
    Just realised that the latest version has an improved ResponseHeader building function.
    So I scrapped my version.

    Still needs the mime-type fixed for "js" and "ico" files though.

    js = application/javascript
    ico = image/x-icon

    also, if the mime-type isn't in the list; "text/plain" should be returned.
  • Mike GMike G Posts: 2,702
    edited 2011-07-05 06:41
    I made the changes to the Response object. For others reading this, file extension and content-type are in parallel DAT tables related by index. The Response object creates a hash on start up that maps the extension to media type. If you add a content-type, make sure the extension lines up by index with the media type.

    I'm returning application/octet-stream if the media type is not listed.
      hashTable     long    $0[30]
      headerMap     long    $0[30]
      extensions    byte    "oct",0,             "xml",0,              "xsl",0,           "shp",0,        "txt",0,  {
      }                     "pdf", 0,            "zip", 0,             "jpg", 0,          "png",0,        "gif",0,  {
      }                     "css",0,              "js",0,              "ico",0,           "wmv",0,        "wav",0,   {
      }                     "htm", 10
      hearerline    byte    "application/octet-stream",0, "text/xml",0,               "text/xml",0,           "text/html",0,       "text/plain; charset=utf-8",0,{
      }                     "application/pdf",0,          "application/zip",0,        "image/jpeg",0,         "image/png",0,       "image/gif",0,                {
      }                     "text/css",0,                 "application/javascript",0, "image/x-icon",0,        "video/x-ms-wmv",0,  "audio/x-wav",0,            {
      }                     "text/html",0
    
Sign In or Register to comment.