Skip to content

A Good Weekend For Serving Doughnuts

March 16, 2015

15-03-16 intro
I had the doughnuts server up on the public internet for a couple of days.  I wouldn’t say it had a lot of traffic but about 25 different IPs played 60 games over the period and almost 500 pages were served.  People that i heard from commented on how responsive it was and no one reported a problem.  Toward the end of the time i got games going on two different computers on the home LAN and I did get an “unable to connect” from safari on two occasions.  

It occurred to me that i could provoke a clash if I input a table print request on one PC and entered a regular transaction from another. This is pretty extreme because it takes the poor thing almost 6 seconds to format the table but it’s highly reliable. Both safari and chrome on the second computer report immediately that they’re unable to connect. It looks like chrome keeps trying though because the transaction goes through once the table print is done; Safari never comes back on its own but clears up with a refresh. Realistically, to handle even a few transactions a minute, I would need to use multiple sockets(and also avoid printing the IP table while anyone’s using the server!).

Both of the initial failure were coming off the congratulations screen which made me look closely at the transaction flow.  Doing this I found a problem that is almost certainly unrelated.

The congrats form is shown below
15-03-16 congrats
The button that says “press to play again” is meant to drive a POST type transaction, just to differentiate it from the other buttons which drive GETs. The html though, is just wrong:

	static unsigned char pform[]="<p><form method=\"PUT\">\r\n"
						"<input type=\"submit\" value=\"Press To Play Again\">\r\n"
						"</form>";

PUT just gets treated as GET – i have no idea how i did that. As it happens though the code in the loop that handles transactions is bullet-proof enough that it doesn’t hurt anything. The default action for an unrecognized input is to start a new game which covers my sin in this instance. Also, the 4th test should have been just for “GET /” and come after the next one to catch any random GET’s without requiring the default to be invoked so that the “mystery meat” clause would actually mean something. As it is, thelog is littered with it.

  			if (strncmp((char *)buf,"POST /",6)==0){
  				bagelsinit(); //initialize game, send the form
			}
			else if (strncmp((char *)buf,"GET /favicon",12)==0){
  				sendnak(); //no favicon here
			}
  			else if (strncmp((char *)buf,"GET /?G=",8)==0){
				bagelsturn();	//give player his turn
			}
  			else if (strncmp((char *)buf,"GET /?G=",8)==0){
				bagelsturn();	//give player his turn
			}
  			else if (strncmp((char *)buf,"GET /T",6)==0){
 				bagelspeek(); //show the IP table
			}
  			else{
				printf("\nmystery meat\n");
 				bagelsinit(0); //initialize game, send the form
			}
  			if (strncmp((char *)buf,"POST /",6)==0){
  				bagelsinit(); //initialize game, send the form
			}
			else if (strncmp((char *)buf,"GET /favicon",12)==0){
  				sendnak(); //no favicon here
			}
  			else if (strncmp((char *)buf,"GET /?G=",8)==0){
				bagelsturn();	//give player his turn
			}
  			else if (strncmp((char *)buf,"GET /T",6)==0){
 				bagelspeek(); //show the IP table
			}
  			else if (strncmp((char *)buf,"GET /",5)==0){
 				bagelsinit(0); //initialize game, send the form
			}
  			else{
				printf("\nmystery meat\n");
 				bagelsinit(0); //initialize game, send the form
			}
		}
Advertisements

From → web server

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: