Angel \”Java\” Lopez on Blog

January 9, 2012

Social Games Programming (Part 8) Adding Node.Js

Filed under: Azure, Game Development, JavaScript, NodeJs — ajlopez @ 7:46 pm

Previous post

In the previous post, we explored the game processing in the current Windows Azure Toolkit for Social Gaming. Now, it’s time to add Node.js as game server, in our Tic Tac Toe simple game.

All the Game Service client code is game agnostic. And it can be changed to use another services. In this post, I will change the play move processing to be directed to a Node.js instance.

You need to download the node folder from my GitHub:

https://github.com/ajlopez/SocialGamingExtensions

Then, follow these steps:

1 – Download and setup the Windows Azure Toolkit for Social Gaming version 1.1.1, from:

http://watgames.codeplex.com/releases/view/77091

1 – Install Node.js for Windows, from http://nodejs.org/#download

2 – Change to the server folder, and execute this command line:

npm install socket.io

The socket.io library is downloaded and installed in a node_modules subfolder:

This is the folder tree:

3 – Start the node.js server:

node gameex.js

The server starts to listen:

4 – Copy the client folder to your SocialGaming.Web project folder. Web.config, BaseController.cs, TicTacToeController.cs files will be replaced. New files will be added: Scripts\game\GameServiceNodeJs.js, Areas\Samples\Views\TicTacToe\NodeJs.cshtml.

5 – Open the solution in Visual Studio 2010 (run as administrator) and add these files to SocialGaming.Web project. The new Game Service for Node.js:

The new TicTacToe view that uses Node.js:

The new action in the replaced TicTacToe controller:

There is a new entry in the web.config file:

The replaced BaseController reads that setting:

6 – Start the application (it should run as http://127.0.0.1:81 to be accepted by the Federated Security running in ACS portal). See the invite URL:

7 – Browse to /Samples/TicTacToe/NodeJs:

8 – The client connects with the Node.js game server:

My browser doesn’t understand the WebSocket version implemented in the socket.io server library. Then, Socket.io fallback to use xhr long polling.

9 – Open a new browser, in a private session, with the URL provided by the step 6

10 – These are the two players. The left one played at top left cell. The right player receives the new move and update its view.

11 – See the server console: the move was received and broadcasted to the game participants:

Nice! Homework: add the Node.js to a worker role (see @ntotten post NodeJS on Windows Azure).

Next topics: explain in detail the server code (it supports client that uses plain TCP sockets instead of socket.io, so you can program a client in other platforms, from Silverlight to iPhone to Android).

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

4 Comments »

  1. [...] by Social Games Programming (Part 8) Adding Node.Js « Angel “Java” Lopez on Blog — January 9, 2012 @ 7:47 pm [...]

    Pingback by Social Games Programming (Part 7) Game Moves Processing « Angel “Java” Lopez on Blog — January 9, 2012 @ 7:47 pm

  2. [...] days, I was working with Node.js and Social Gaming. There is more support for Windows (now we have npm) and for Azure. My new [...]

    Pingback by Node.Js: Links, News And Resources (5) « Angel “Java” Lopez on Blog — January 10, 2012 @ 7:06 pm

  3. I was wondering if you ever thought of changing the page layout of your website?
    Its very well written; I love what youve got to say. But maybe
    you could a little more in the way of content so people could connect
    with it better. Youve got an awful lot of text for only having one or two pictures.
    Maybe you could space it out better?

    Comment by Trusted Online Casinos — July 19, 2013 @ 10:06 am

  4. So for this is mostly done on shared servers. click here If the size or loudness of the web pages are
    immense than the compulsive bandwidth capacity,
    the web page would be offer to substitution valuable data in patronage for the user’s e-mail address.

    Comment by electronic cigarette — August 7, 2013 @ 9:34 am


RSS feed for comments on this post. TrackBack URI

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

The Shocking Blue Green Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 66 other followers

%d bloggers like this: