Monday, December 1, 2014

Done with the Web Server! (Week 48)

So I managed to finish my web server. 

When I started coding I managed to get something up and working in a few hours and I blogged about it last week, but then I realized that there was much more to assignment 2 so I got down to business.

First of all I had to figure out how a web browser operates. Something I knew nothing about. My classmate Jonas explained how the browser sends a “GET” request (e.g. GET / HTTP1.1) to the server and how search paths works when you only use your IP-address in the search field of the browser.

Understanding that I managed to get the information sent by the web browser and saved that info into a buffer. From the buffer I could read what kind of things the browser requested and supported.

I started with managing a simple get request.  When someone enters my web server IP-address I answer by sending header information about the server.

http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

Only a few of these header fields has to be included in the header info the server sends. Content type and the content length is something that needs to be included.

The info that is sent has to be EXACTLY correct or the page never finish loading or don’t load at all. I thought it didn’t matter because I only sent strings with text in them.  It took about a week figuring out that this was what caused most of my troubles. This is what I finally included as my header info:


Another big problem I had was to figure out how to handle timeouts or disconnects from the client side. First I went around this problem by just sending information to the client to see if it arrives, like a “ping” but that felt strange to do every loop so I kept looking for other ways and I found this website


explaining that there is no real sure way to know that the client has lost connection unless the server and client are both programmed to handle this. But since I only make the server side I can’t do that.


So I went with just keeping a timer that updates only when a user sends data to the server. If no data is sent for five minutes the server cuts the connection to the client

























..…but in our assignment it says that we have to respect the browsers connection header so I extracted the information of the connection status from the web browser that is stored in my receiving data buffer and I set the client to keep alive if it’s a keep alive connection and to closed if it’s a closed connection.


I chose to include both capital and small letters in my control because I noticed that the browsers sent different information.

That’s it for this week. I will start with assignment 3 next week. Making a 3D engine and a game….Alone! so that’s a challenge.


No comments:

Post a Comment