10 February 2010

A nice asynchronous bit of coms

In letterscore/createWords I realized that the text input was being laggy: this is because javascript is single threaded and must wait while the synchronous message was being sent.

Here is my solution:

The client and server both start out with

communications_number = 0

The client sends the request asynchronously to the server, along with its current communications_number

When the server receives a request, it checks the communications number.
If this number is equal to the current number, then the server increments its communications_number.
Otherwise, it does not.

Then the server sends the response back with its current communication_number.

When the client gets the server's communication_number, it checks whether or not this number is greater than its current communication_number.

If it isn't greater, then this is an old packet and we skipped a couple of numbers; we have already processed a newer packet!

If it is greater, then its a new packet, and so we set our communication_number = the server's communication_number.

In this way the client can arrange the old and new data appropriately; it is easy to see how when you know the ordering of things, quite apart from when you actual received them, that you can reconstruct them into an ordered set.

Or in other words, we can have sequential behaviour without having to wait for sequential computations to finish!

I think I might wrap this behaviour up in a javascript prototype object!

9 February 2010

Letterscore!

Letterscore is a new super fun web game by me!

Check it out at letterscore.co.uk!

You play against another human player from somewhere on the Internet. First you choose ten letters; each letter is randomly determined but you decide whether or not it is a vowel or a consonant.

Then you make a word.

Then the game tells you whose word is longer, or whose word is not a word!

The objective is to climb the league.

It's lots of fun; and has everyone giggling.

(And is kinda like the television program countdown)