Monkey-X and Connecting to Your Server

While traveling to visit family this past weekend I was attempting to set up a simple high score server for Prism Ship. I decided to use Sinatra for the backend because it would allow me to make a very simple and quick server using only a couple of lines since I don’t need an interface of any kind. Little did I know this simple task would turn out to take several hours.

This was partly caused by my lack of familiarity with Monkey-X and partly allergies.

Backstory

I was staying with some relatives and the females all went shopping and what not. My brother-in-law had made plans to spend the afternoon gaming at a friends house (Dark Souls II anyone?) so I tagged along figuring I would just program while they played. Better than sitting in an empty apartment for 5 hours right?

I had been to this friends house before but forgot about the pets. Normally I don’t have any problems with dogs or cats and didn’t the last time I was there (which was probably because we spent a majority of the time outside on that visit). However, this visit caused very annoying allergy type symptoms to be present for 4.5/5 hours.

Now, the server was simple enough to set up. Just a few lines of Ruby using Sinatra to test.

require 'sinatra'

get '/' do
body "High Score List"
end

It’s really that simple.

First Problem – Different Domains

I noticed that despite following the instructions in the documentation for the brl.httprequest module in Monkey-X, I was not getting expected output. So I opened the dev tools in the browser and saw this:
Access-Control-Allow-Origin: access denied
After a brief investigation, it seemed to be related to CORS (Cross Origin Resource Sharing). It was caused by trying to run the game on the localhost and accessing the Sinatra server running on Heroku. This is fixed with a little addition to the Ruby code:
require 'sinatra'

get '/' do
response.headers['Access-Control-Allow-Origin'] = "*"
body "High Score List"
end

This is not very secure, but it fits our purposes for the time being.

Second Problem – Not Carefully Reading Documentation

A nose that is running because of excessive cat and dog dander will keep you from thinking straight and reading carefully. I missed an important line in the HttpRequest documentation that says – “Your application must continously call UpdateAsyncEvents at regular intervals (for example, once per OnUpdate) while an http request operation is in progress for it to complete.”

My little program was sending just fine, I could see the server send back a nice HTTP:200 code, but the game would not fire the OnHttpComplete method.

The very next time I sat down to work on this problem, it took less than 5 minutes of googling and reading to find the cause. I put the UpdateAsyncEvents line in and everything just started working.

Moral of the story

Read documentation carefully and try not to program somewhere that will cause you to have a runny nose (or other types of distractions).

I Want to Be a Better Developer

One thought on “Monkey-X and Connecting to Your Server

  1. Pingback: Putting Your Work Online | Evolving Developer

Comments are closed.