Angel \”Java\” Lopez on Blog

February 13, 2012

Azure: Links, News and Resources (3)

Filed under: .NET, Azure, Cloud Computing, Links — ajlopez @ 1:54 pm

Previous Post

More links I collected during my work and research.

Cyan – Simpler than Azure
http://cyannet.codeplex.com/
Cyan is a .NET dynamic client for the Azure Table Storage REST API.

Azure Table Storage & Dynamic TableServiceEntity
http://stackoverflow.com/questions/7522235/azure-table-storage-dynamic-tableserviceentity

richorama / AzureSugar
https://github.com/richorama/AzureSugar
Syntactic sugar to make Azure development a little sweeter
Support is also available for using dynamic types (or dictionaries) to insert and query table storage.

Azure Table Storage with dynamic entities objects
http://ruiromanoblog.wordpress.com/2009/05/15/azure-table-storage-with-dynamic-entities-objects/

WindowsAzure / azure-sdk-for-node
https://github.com/WindowsAzure/azure-sdk-for-node/tree/dev/examples/myevents

Accessing Azure Role Environment information from NodeJS
http://nodeblog.cloudapp.net/accessing-azure-role-environment-information-from-node

Windows Azure Startup task to run npm install to avoid deploying node modules
http://nodeblog.cloudapp.net/startup-task-to-run-npm-in-azure

Leveraging Node.js’ libuv in Windows Azure
http://msdn.microsoft.com/en-us/library/hh527737(v=VS.103).aspx

Getting the samples to work on the Azure Node.js SDK
http://coderead.wordpress.com/2012/01/03/getting-the-samples-to-work-on-the-azure-node-js-sdk/

Microsoft will add Linux virtual machines to Windows Azure
http://arstechnica.com/business/news/2012/01/microsoft-will-add-linux-virtual-machines-to-windows-azure.ars

Create Hosted Service using Windows Azure Management API
http://debugmode.net/2012/01/02/create-hosted-service-using-windows-azure-management-api/

Microsoft Windows Azure PaaS Gets Node.js Update
http://www.talkincloud.com/microsoft-windows-azure-paas-gets-node-js-update/

How to deploy WordPress using the Windows Azure SDK for PHP WordPress scaffold
http://azurephp.interoperabilitybridges.com/articles/how-to-deploy-wordpress-using-the-windows-azure-sdk-for-php-wordpress-scaffold

Advertising Company Adopts Cloud Computing, Gets 400 Percent Improvement
http://www.microsoft.com/casestudies/Case_Study_Detail.aspx?CaseStudyID=4000008145

Kobojo
Game Developer Meets Demand and Prepares for Success with Scalable Cloud Solution
http://www.microsoft.com/casestudies/Case_Study_Detail.aspx?CaseStudyID=4000008216

What is Windows Azure?
http://www.youtube.com/watch?feature=player_embedded&v=poDRw_Xi3Aw

Azure On GitHub
https://github.com/blog/1010-azure-on-github

Azure: Running Multiple Web Sites in a Single WebRole
http://blog.elastacloud.com/2011/01/11/azure-running-multiple-web-sites-in-a-single-webrole/

Deploying independent web applications to Windows Azure using single web role
http://weblogs.asp.net/gunnarpeipman/archive/2011/12/29/deploying-independent-web-applications-to-windows-azure-using-single-web-role.aspx

Modificar el tiempo de vida del token proporcionado por Windows Azure AppFabric Access Control
http://www.returngis.net/2011/12/modificar-el-tiempo-de-vida-del-token-proporcionado-por-windows-azure-appfabric-access-control/

Windows Azure Multi Application
http://azuremultiapp.codeplex.com/
Windows Azure Multi Application is a complete sample solution that allow deploy dinamically aplications to existing role instance.
After deploy admin tool new application can be deployed, without modify initial azure deployment. Each application can be deployed independently and can be of different types; ASP.NET WebForms, ASP.NET MVC, Windows Service, Console Application…

How to combine a Worker Role and an MVC4 Web Role into a single Azure instance
http://blog.liamcavanagh.com/2011/12/how-to-combine-a-worker-role-with-a-mvc4-web-role-into-a-single-instance/

Hadoop Streaming and F# MapReduce
http://blogs.msdn.com/b/carlnol/archive/2011/12/16/hadoop-streaming-and-f-mapreduce.aspx

Windows Azure Architecture Guide – Part 2 – Code Samples
http://www.microsoft.com/download/en/details.aspx?id=27878

Windows Azure + a pinch of UK
http://paper.li/ericnel/1314797915

Using Amazon and Azure Cloud Services in your Delphi XE2 and C++Builder XE2 Applications
http://www.youtube.com/watch?v=BRFbiRcLtkc&feature=player_embedded

What’s new in Windows Azure
http://www.infoworld.com/d/microsoft-windows/whats-new-in-windows-azure-181578

Microsoft Azure gets an open source rival
http://www.infoworld.com/d/open-source-software/microsoft-azure-gets-open-source-rival-181845

Introduction to the Hadoop on Azure Interactive JavaScript Console
http://www.youtube.com/watch?v=alPMYcomUEs

Node.JS in Windows Azure
http://channel9.msdn.com/Events/windowsazure/learn/Node-JS-in-Windows-Azure

Azure price cuts, bigger databases, now with node.js and MongoDB support, Hadoop on its way
http://arstechnica.com/microsoft/news/2011/12/azure-price-cuts-bigger-databases-now-with-nodejs-and-mongodb-support-hadoop-on-its-way.ars?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+arstechnica/index+(Ars+Technica+-+Featured+Content)

Improved Developer Experience, Interoperability, and Scalability on Windows Azure
http://blogs.msdn.com/b/windowsazure/archive/2011/12/12/improved-developer-experience-interoperability-and-scalability-on-windows-azure.aspx

Azure Node.js Developer Center
https://www.windowsazure.com/en-us/develop/nodejs/

Deploying Node.js Applications to Windows Azure via Blobs or Git Sync
http://blog.smarx.com/posts/deploying-node-js-applications-to-windows-azure-via-blobs-or-git-sync

Ten Basic Troubleshooting Tips for Windows Azure
http://www.davidaiken.com/2011/11/15/ten-basic-troubleshooting-tips-for-windows-azure/

Now Available! Updated Windows Azure SDK & Windows Azure HPC Scheduler SDK
http://blogs.msdn.com/b/windowsazure/archive/2011/11/14/updated-windows-azure-sdk-amp-windows-azure-hpc-scheduler-sdk.aspx

My Links
http://delicious.com/ajlopez/azure

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

January 7, 2012

Social Games Programming (Part 7) Game Moves Processing

Filed under: .NET, Azure, Game Development, JavaScript — ajlopez @ 5:24 pm

Previous Post
Next Post

In this post, I want to discuss the game play processing in Tic Tac Toe. It involves many pieces, from Razor view using Javascript to Web Role, to Azure Blob Storage.

These are the javascript files referenced in Tic Tac Toe view (at SocialGame.Web/Areas/Samples/Views/TicTacToe/Index.cshtml):

<script src="@Url.AreaContent("Scripts/jQuery.tmpl.js")" type="text/javascript"></script>
<script src="@Url.AreaContent("Scripts/knockout-1.2.1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/game/ServerInterface.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/game/GameService.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/game/UserService.js")" type="text/javascript"></script>
<script src="@Url.AreaContent("Scripts/game/TicTacToeBoard.js")" type="text/javascript"></script>
<script src="@Url.AreaContent("Scripts/game/TicTacToeGame.js")" type="text/javascript"></script>
<script src="@Url.AreaContent("Scripts/game/TicTacToeViewModel.js")" type="text/javascript"></script>
<script src="@Url.AreaContent("Scripts/game/TicTacToeController.js")" type="text/javascript"></script>

As I wrote in the previous post, ServerInterface, GameService and UserService are game-agnostic components. They could be used in any game. For each new kind of game X, you must implement XBoard, XGame logic, XViewModel and an appropiate XController.

At the end of that view, there is the creation of the game-agnostic services:

var apiURL = "@this.ViewBag.ApiUrl";
var blobURL = "@this.ViewBag.BlobUrl";
var si = new ServerInterface();
var gs = new GameService(apiURL, blobURL, si);
var user = new UserService(apiURL, blobURL, si);

The @this.ViewBag properties are filled in the ASP.NET MVC controller (see BaseController.cs)

The creation of the game controller:

// check for canvas, show an "Upgrade your browser" screen if they don't have it.
var canvas = document.getElementById('board');
if (canvas.getContext == null || canvas.getContext('2d') == null) {
    $("#game").toggle();
    $("#notSupported").toggle();
    return;
}
var board = new TicTacToeBoard(canvas);
var game = new TicTacToeGame();
var controller = new TicTacToeController(viewModel, gs, board, game);
controller.setGameQueueId(gameQueueId);
controller.start();

But the interesting part is in the controller constructor:

function TicTacToeController(viewModel, gameService, board, game) {
    this.viewModel = viewModel;
    this.gameService = gameService;
    this.board = board;
    this.game = game;
    this.started = false;
    var controller = this;
    this.board.onMove = function (x, y) { controller.onMove(x, y); };
};

Notice the this.board.onMove: the controller register itself to process new moves detected by the board component. At its start method, the controller register itself to process game service updates:

controller.gameService.process(
        gameQueueId,
        function (queue) { controller.processGameQueue(queue); },
        function (action) { controller.processAction(action); }
        );

Let’s examine the processing of game moves.

1 – The board component detects a click, then it sends a new move to controller (using the onMove callbalk)

2 – The controller sends the new move to game logic, to update state (I omitted the view model in this sequence/graph)

3 – The controller sends the new move to game service.

4 – The game services sends a new command to web role, using the server interface

5 – The Web Role API receives the new command

6 – The command info is appended to the game status blob, at Azure storage

Now, the other client processing:

1 – The game service, using a timer, polls the game status, calling the service interface

2 – The service interface, using JSONP, retrieves the current game status from Azure Blob storage

3 – If a new move is detected, the game service calls a callback function provided by the controller (game service has no reference to controller).

4 – The controller sends the new move to game logic, updating state (I omitted the view state here)

5 – The controller sends the new move to board component, to update the canvas

A key point: the controller knows NOTHING about the service interface, WCF Web API, blob storage. So, you can change the game service to route and detect new moves in other ways. Next post: modify game service to use a Node.js server for game move processing.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

January 3, 2012

What is Windows Azure?

Filed under: Azure, Cloud Computing, Video — ajlopez @ 11:06 am

Past year, I wrote many blog post about Azure programming. Maybe, you know about cloud computing in general, but not about Azure in particular. Today, thanks to Windows Azure + a pinch of UK published by Eric Nelson (@ericnel), I found this video, that explain in simple terms the key technical pieces of Azure:

http://www.youtube.com/watch?v=poDRw_Xi3Aw

For more information about the video, see Steve Marx (@smarx) post:

What is Windows Azure? (a Hand-Drawn Video)

It has an interesting section title: “How I Made It”.

Notice the difference of compute nodes and storage nodes. Both service can be emulated in your local machine, thanks to Azure tools for Visual Studio.

My links about azure:

http://delicious.com/ajlopez/azure

A post about Azure, games and Node.js is comming.

Keep tuned!

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

December 19, 2011

Social Games Programming (Part 6) Testing Game and Service with TDD and QUnit

Filed under: .NET, Azure, Game Development, QUnit, Test-Driven Development — ajlopez @ 8:44 am

Previous Post
Next Post

In my previous post, I presented the new version of Windows Azure Toolkit for Social Games. It has simple games to demonstrate the use of Javascript, HTML 5 canvas, game moves processing, Azure worker roles and web roles. Let’s explore in this post the making of client game logic, in Javascript, using TDD and QUnit.

There are online tests at:

http://watgames4.cloudapp.net/Test

Let’s run the Tic Tac Toe Game Logic tests:

http://watgames4.cloudapp.net/Samples/ClientTest/TicTacToeGameTest

This page is using QUnit for client Javascript unit testing. I wrote about that library at:

TDD with Javascript and QUnit

The above page is testing the Tic Tac Toe logic. Remember, each game is implemented in parts, the logic is one of them:

The client code resides in TicTacToeGame.js inside the SocialGames.Web project. Their first lines:

TTTColor = { Empty: 0, Cross: 1, Circle: 2 };
function TicTacToeGame() {
    this.board = [
     [TTTColor.Empty, TTTColor.Empty, TTTColor.Empty],
     [TTTColor.Empty, TTTColor.Empty, TTTColor.Empty],
     [TTTColor.Empty, TTTColor.Empty, TTTColor.Empty]
     ];
}
TicTacToeGame.prototype.move = function (x, y, color) {
    this.board[x][y] = color;
};
TicTacToeGame.prototype.isEmpty = function (x, y) {
    return this.board[x][y] == TTTColor.Empty;
};
....

The client test page (TicTacToeGameTest.cshtml) was built at the same time, using a TDD (Test-Driven Development) approach. Look at first tests:

test("Create Empty Board", function () {
    var game = new TicTacToeGame();
    for (var x = 0; x < 3; x++)
        for (var y = 0; y < 3; y++)
            ok(game.isEmpty(x, y));
    equal(game.isTie(), false);
    equal(game.hasWinner(), false);
});
test("Valid Moves on Empty Board", function () {
    var game = new TicTacToeGame();
    for (var x = 0; x < 3; x++)
        for (var y = 0; y < 3; y++) {
            ok(game.isValid(x, y, TTTColor.Cross));
            ok(game.isValid(x, y, TTTColor.Circle));
        }
});
test("No Winner in Empty Board", function () {
    var game = new TicTacToeGame();
    equal(game.getWinner(), TTTColor.Empty);
});
test("Get Winner in First Row", function () {
    var game = new TicTacToeGame();
    game.move(0, 0, TTTColor.Cross);
    game.move(1, 0, TTTColor.Cross);
    game.move(2, 0, TTTColor.Cross);
    equal(game.getWinner(), TTTColor.Cross);
    equal(game.isTie(), false);
    equal(game.hasWinner(), true);
});

The idea is to take baby steps, one test at a time, designing the game logic “API”, its expected behavior. In this way, you expend less time debugging in a dynamic language like Javascript, and you gain a test suite that can save your day in case of major refactoring. Look at the Four In A Row logic and client tests: you will find a similar approach.

Ok, not all can be easily tested, or build using TDD. Some of the game-agnostic services are using Ajax and Blob Storage, and to test them you must consider asynchronous Ajax calls. You can check:

http://watgames4.cloudapp.net/Test/ServerInterfaceTest

(You must be logged in using your Facebook or Windows Live ID, an example of use of Federated Security and Access Control Service (ACS))

This time, the system under test is the game-agnostic Server Interface:

There are some tricks in the test code (ServerInterfaceTest.cshmlt), an excerpt:

test("Call User/Verify", function () {
    var success = function (result) { ok(true); start(); };
    var error = ajaxGetError;
    stop(10000);
    expect(1);
    si.sendAjaxGet(apiURL + "user/verify", success);
});

expect is a QUnit function that prepare the framework to receive 1 ok(true) sometime during the test run. That confirmation is included in callback function success that it will be called after the successful processing of the asynchronous call .sendAjaxGet. Async life is not easy ;-)

More code analysis is coming. And some adapt to use Node.js as game server.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

November 30, 2011

Social Online Games Programming (Part 5) New Azure Toolkit

Previous Post
Next Post

Two weeks ago, a new version of Windows Azure Toolkit for Social Games was released. See @ntotten posts:

Windows Azure Toolkit for Social Games Version 1.1.1
Windows Azure Toolkit for Social Games Version 1.1

The new version implements two simple HTML5 games: tic-tac-toe and four-in-a-row, backed up by ASP.NET MVC views, WCF Web API services, ACS federated security, and Azure Storage. You can play them online at:

http://watgames4.cloudapp.net/

I think this is a more clear example than the previous one (Tankster) that was great but a bit overwhelming ;-). Let’s dive into some implementation details of this new example.

Totten wrote:

The biggest change we have made in this release is to separate the core toolkit from the Tankster game. After we released the Tankster sample game we received a lot of feedback asking for a simpler game that developers could use to learn. To meet this need we developed two simple games, Tic-Tac-Toe and Four in a Row, and included in the toolkit. The Tankster game is now available separately as a sample built on top of the toolkit.

While the new games included in the toolkit are much simpler than Tankster, they still show the same core concepts. You can easily use these samples as a starting point to build out any number of types of games. Additionally, you will find that many of the core components of the game such as the leaderboard services, game command services can be used without any modification to the server side or client side code.

In my previous post, I mentioned a minor but important change in game action processing: any game logic was removed from server code. Adopting this approach, you can write new games without changing the ASP.NET MVC code. You still can add server side code if you want (to have more control over the actions, to avoid player cheating, etc..) but it is interesting to have a base code with game-agnostic code.

Opening the solution in Visual Studio, you will find Javascript files used by the two games. You can write a new game, reusing these files:

The games are implemented as areas:

You could add new games and publish them as NuGet packages.

Visually, the client Javascript code is organized as:

Each game X (TicTacToe, FourInARow, yours) has:

- XGame: the game logic

- XBoard: to draw board on canvas and to detect click events on it

- XViewModel: containing the player and other data to be used at view rendering (the example uses knockout.js, an MVC in Javascript)

- XController: to process new events and to coordinate the above elements

The generic part:

- UserService: methods related to users: login, get friends, etc.

- GameService:  play moves, receives new moves, other actions.

- ServerInterface: Ajax calls (using GET, POST, JSONP, Azure storage…) that are used by the implemention of User and Game Service.

Topics for next posts: analyze the Javascript code, the use of Canvas, Javascript tests using QUnit, communication with server using Ajax, change the Game Service (Javascript) to use a Node.js server.

Keep tuned!

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

November 21, 2011

Azure: Links, News and Resources (2)

Filed under: Azure, Cloud Computing, Links — ajlopez @ 9:22 am

Previous Post
Next Post

More links related to Azure:

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

The Windows Azure Platform[2] is a Microsoft cloud platform used to build, host and scale web applications through Microsoft data centers. Windows Azure Platform is thus classified as platform as a service and forms part of Microsoft’s cloud computing strategy, along with their software as a service offering, Microsoft Online Services. The platform consists of various on-demand services hosted in Microsoft data centers and commoditized through three product brands. These are Windows Azure[3] (an operating system providing scalable compute and storage facilities), SQL Azure (a cloud-based, scale-out version of SQL Server) and Windows Azure AppFabric (a collection of services supporting applications both in the cloud and on premise).

Moving Channel9.msdn.com to Windows Azure
http://www.infoq.com/articles/Channel-9-Azure

Build 2011: Windows Azure Tackles the ‘One True Login’ Puzzle
http://www.readwriteweb.com/cloud/2011/09/build-2011-windows-azure-tackl.php

Microsoft to eat its own cloud dog food with Photosynth
http://www.zdnet.com/blog/microsoft/microsoft-to-eat-its-own-cloud-dog-food-with-photosynth/11104

Command-Query Separation on Windows Azure
http://ntotten.com/2011/10/command-query-separation-on-windows-azure/

How to Manage Expiration of Blob Content
http://msdn.microsoft.com/en-us/library/windowsazure/gg680306.aspx

Windows Azure Design Patterns, Part 1: Architectural Symbols
http://davidpallmann.blogspot.com/2011/07/windows-azure-design-patterns-part-1.html

Windows Azure Accelerator for Web Roles Version 1.1
http://ntotten.com/2011/08/windows-azure-accelerator-for-web-roles-version-1-1/

Running Processes in Windows Azure
http://ntotten.com/2011/09/running-processes-in-windows-azure/

pekkah / AzureSamples
https://github.com/pekkah/AzureSamples/tree/master/DataSample

Exercise 1: Using Worker Role External Endpoints
http://msdn.microsoft.com/en-us/gg457890

Building Web APIs in Windows Azure with WCF to reach any device
http://channel9.msdn.com/Events/BUILD/BUILD2011/SAC-798T

pofallon / node-azure
https://github.com/pofallon/node-azure
A node.js library for accessing the Windows Azure REST API’s

Introducing Geo-replication for Windows Azure Storage
http://blogs.msdn.com/b/windowsazurestorage/archive/2011/09/15/introducing-geo-replication-for-windows-azure-storage.aspx

Windows Azure Tables: Introducing Upsert and Query Projection
http://blogs.msdn.com/b/windowsazurestorage/archive/2011/09/15/windows-azure-tables-introducing-upsert-and-query-projection.aspx

Windows Azure Blobs: Improved HTTP Headers for Resume on Download and a Change in If-Match Conditions
http://blogs.msdn.com/b/windowsazurestorage/archive/2011/09/15/windows-azure-blobs-improved-http-headers-for-resume-on-download-and-a-change-in-if-match-conditions.aspx

CloudCopy Command Line Tool
http://cloudcopy.codeplex.com/

Windows Azure Toolkits for Devices – Now With Android!
http://www.wadewegner.com/2011/08/windows-azure-toolkits-for-devices-now-with-android/

Microsoft rolls out Windows Azure toolkit for Android
http://www.zdnet.com/blog/microsoft/microsoft-rolls-out-windows-azure-toolkit-for-android/10503

Windows Azure SDK for PHP
http://blogs.msdn.com/b/mvplead/archive/2011/08/31/windows-azure-sdk-for-php.aspx

Azure Tip: Consider Remote Desktop when Planning Role Endpoints
http://www.davidmakogon.com/2011/01/azure-tip-consider-remote-desktop-when.html

Memcached in Windows Azure
http://blog.smarx.com/posts/memcached-in-windows-azure

NodeJS on Windows Azure
http://ntotten.com/2011/08/nodejs-on-windows-azure/

Using Windows Azure to use as a TCP Server
http://stackoverflow.com/questions/6173763/using-windows-azure-to-use-as-a-tcp-server

Windows Azure Tip: Go Beyond 5 Endpoints per Role, beyond 25 per Deployment
http://www.davidmakogon.com/2011/05/windows-azure-tip-go-beyond-5-endpoints.html

Lightweight Tracing to Windows Azure Tables
http://blog.smarx.com/posts/lightweight-tracing-to-windows-azure-tables

Using ELMAH in Windows Azure with Table Storage
http://www.wadewegner.com/2011/08/using-elmah-in-windows-azure-with-table-storage/

Windows Phone 7 Push Notification QuickApp / Web Service (With Azure Publishing Instructions!)
http://channel9.msdn.com/posts/Windows-Phone-7-Push-Notification-QuickApp–Web-Service-With-Azure-Publishing-Instructions

Various Options to Manage Session State in Windows Azure
http://geeks.netindonesia.net/blogs/wely/archive/2011/08/13/various-options-to-manage-session-state-in-windows-azure.aspx

Windows Azure & WF 4.0 – Creating a Workflow-Driven WorkerRole
http://agileculture.net/lboffi/2011/08/12/windows-azure-wf-40-creating-a-workflow-driven-workerrole/

Microsoft announced Windows Azure Storage Analytics
http://bartwullems.blogspot.com/2011/08/microsoft-announced-windows-azure.html

Azure Cloud to Capture RenderMan
http://www.hpcinthecloud.com/hpccloud/2011-08-08/azure_cloud_to_capture_renderman.html

igrating SQL server Data to SQL Azure using BCP << Paras Doshi
http://beyondrelational.com/blogs/parasdoshi/archive/2011/08/08/migrating-sql-server-data-to-sql-azure-using-bcp-lt-lt-paras-doshi.aspx

Using Windows Azure Blob Storage and CDN with WordPress
http://www.wadewegner.com/2011/08/using-windows-azure-blob-storage-and-cdn-with-wordpress/

Practical Testing Techniques for Windows Azure Applications
http://www.devproconnections.com/article/cloud-computing2/cloud-test-windows-azure-136179

Daytona: Iterative MapReduce on Windows Azure
http://research.microsoft.com/en-us/projects/daytona/default.aspx

Connecting to SQL Azure from Ruby Applications
http://msdnrss.thecoderblogs.com/2011/08/connecting-to-sql-azure-from-ruby-applications/

Ideas about NoSql on Windows Azure: Azure Storage
http://blog.fabse.net/2011/08/02/ideas-about-nosql-on-windows-azure-azure-storage/

Architecture of Tankster– Scale (Part 2)
http://ntotten.com/2011/07/architecture-of-tankster-scale-part-2/

Windows Azure CDN Helpers
http://ntotten.com/2011/06/windows-azure-cdn-helpers/

Social Gaming on Windows Azure
http://channel9.msdn.com/Series/Social-Gaming-on-Windows-Azure

Extending the Windows Azure Accelerator for Web Roles with PHP and MVC3
http://ntotten.com/2011/07/extending-the-windows-azure-accelerator-for-web-roles-with-php-and-mvc3/

Ajax, Cross Domain, jQuery, WCF Web API or MVC, Windows Azure
http://blogs.southworks.net/mwoloski/2011/07/02/ajax-cross-domain-jquery-wcf-web-api-or-mvc-windows-azure/

smarx / blobedit
https://github.com/smarx/blobedit
Simple UI (based on Ace) to edit code files in Windows Azure blob storage

sriramk / winazurestorage
https://github.com/sriramk/winazurestorage
Python client wrapper for Windows Azure storage

Azure BlobStorage Javascript Library
http://azureblobstoragejs.codeplex.com/

Using Windows Azure Page Blobs and How to Efficiently Upload and Download Page Blobs
http://blogs.msdn.com/b/windowsazurestorage/archive/2010/04/11/using-windows-azure-page-blobs-and-how-to-efficiently-upload-and-download-page-blobs.aspx

Building Java applications on Windows Azure gets easier with the new version of the Eclipse plugin
http://blogs.msdn.com/b/interoperability/archive/2011/06/23/building-java-applications-on-windows-azure-gets-easier-with-the-new-version-of-the-eclipse-plugin.aspx

My Links
http://delicious.com/ajlopez/azure

Keep tuned!

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

September 1, 2011

Playing With NodeJs (1) Running on Windows (and Azure)

Filed under: Azure, JavaScript, NodeJs — ajlopez @ 11:17 am

Up until some weeks ago, the only way to run NodeJs on Windows were to download it from the Git repo and compile it using CygWin (another case of get the bananas AND get the monkey).

Building node.js on Cygwin (Windows)
How to install Node.js on Windows

But now there is an alternative: NodeJs team has published a Windows pre-compiled version (0.5.4 and 0.5.5):

http://nodejs.org/#download
http://nodejs.org/dist/
http://nodejs.org/dist/v0.5.4/node.exe
http://nodejs.org/dist/v0.5.5/node.exe

(there is a new version http://nodejs.org/dist/v0.5.5/node-186364e.exe)

I’m using the 0.5.4. Let’s run a simple demo that use Socket.IO:

The Socket.IO module is missing. npm is the “standard” package manager for NodeJs, but there is no Windows version yet:

how can i do npm on windows!

So, you can download the module and its dependencies. See:

Node.js on Windows: Who Needs NPM?

Where are the URLs of the dependencies repos? You can look at

http://search.npmjs.org/

I downloaded some modules, this is my current setup:

These are subdirectories of the directory where node.exe resides. The key file to read in each module is its Package.json. This is the manifest of Socket.IO:

{
    "name": "socket.io"  , 
    "version": "0.7.9"  ,
    "description": "Real-time apps made cross-browser & easy with a WebSocket-like API"  ,
    "homepage": "http://socket.io"  , 
    "keywords": ["websocket", "socket", "realtime", "socket.io", "comet", "ajax"]  , 
    "author": "Guillermo Rauch <guillermo@learnboost.com>"  , 
    "contributors": [        
	{ "name": "Guillermo Rauch", "email": "rauchg@gmail.com" }      , 
        { "name": "Arnout Kazemier", "email": "info@3rd-eden.com" }      ,
        { "name": "Vladimir Dronnikov", "email": "dronnikov@gmail.com" }
     ]  ,
     "repository":{
	    "type": "git"      , 
        "url": "https://github.com/LearnBoost/Socket.IO-node.git"    
     }  ,
     "dependencies": {
        "socket.io-client": "0.7.9"      ,
        "policyfile": "0.0.4"      , 
        "redis": "0.6.6"    
     }  ,
     "devDependencies": {
        "expresso": "0.7.7"      ,
        "should": "0.0.4"      , 
        "assertvanish": "0.0.3-1"
    }  ,
     "main": "index"  , 
     "engines": { "node": ">= 0.4.0" }
}

When I had all the modules, I set the NODE_PATH variable and ran the app again:

Triumph of mind over matter! ;-) This was my first way. But the recommended alternative is to put all the modules in a node_modules subdirectory:

In this way, you don't need the NODE_PATH environment variable. I'm using NODE_PATH because I have my own modules under development in other directories. But if you have a node_modules subdirectory, NodeJs (>0.5 I guess) looks in that subdirectory for modules AND in NODE_PATH. Then I can use NODE_PATH=c:\Git where my AjFabriq module is under development. NodeJs will find Socket.IO in its node_modules subfolder, and my AjFabriq in c:\Git\ajfabriq.

If you have problems with dependencies, read @cibrax post:

Running the “Express” web development framework on Node for Windows

There is a Python clone of npm to install NodeJs packages.

There is a way to run NodeJs from IIS. Check @shanselman post:

Installing and Running node.js applications within IIS on Windows - Are you mad?

An interesting alternative in ASP.NET:

Asynchronous scalable web applications with real-time persistent long-running connections with SignalR

Well, and if you want to run NodeJs on Azure? Oh! I would like to write a post about that topic, but @ntotten have stolen my idea ;-). Read:

NodeJS on Windows Azure

Other posts about NodeJs and Azure:

Node.js, Ruby, and Python in Windows Azure: A Look at What’s Possible | MIX11 | Channel 9

http://channel9.msdn.com/Events/MIX/MIX11

Node.js, Ruby, and Python in Windows Azure: MIX Talk

http://blog.smarx.com/posts/node-js-ruby-and-python-in-windows-azure-my-mix-talk

Related posts about NodeJs:

Node.Js: Links, news, Resources (2)

Node.Js: Links, news, Resources (1)

Playing with Node.js, Ubuntu, Sqlite3 and node-Sqlite

My links:

http://www.delicious.com/ajlopez/nodejs

More playing with NodeJs is coming.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

August 8, 2011

Social Online Games Programming (Part 4) Processing arbitrary Game Actions

Filed under: .NET, ASP.NET MVC, Azure, Game Development, HTML5, JavaScript — ajlopez @ 8:49 am

Previous Post
Next Post

There is a new release of Windows Azure Toolkit for Social Games:

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

Let examine a key change in this version. There is a new entry at Tankster.GamePlay\Services\IGameService.cs:

[WebInvoke(Method = "POST", UriTemplate = "command/{gameId}")]
HttpResponseMessage Command(Guid gameId, HttpRequestMessage request);
[WebInvoke(Method = "POST", UriTemplate = "command/v2/{gameId}")]
HttpResponseMessage Command2(Guid gameId, HttpRequestMessage request);

There are TWO entry points to send game commands from client. Why? Having two URIs the server can be used by old clients and new ones. Note the “v2” in the UriTemplate.

The new Command2 (partial) code at implementation (GameService.cs):

// Add gameAction
var gameAction = new GameAction
{
    Id = Guid.NewGuid(),
    Type = commandType,
    CommandData = commandData,
    UserId = this.CurrentUserId,
    Timestamp = DateTime.UtcNow
};
// Cleanup game actions lists
for (int i = 0; i < game.GameActions.Count(); i++)
{
    if (game.GameActions[i].Timestamp < DateTime.UtcNow.AddSeconds(-10))
    {
        game.GameActions.RemoveAt(i);
        i--;
    }
}
game.GameActions.Add(gameAction);
this.gameRepository.AddOrUpdateGame(game);
return SuccessResponse;

If you compare the old code (Command method) with the above code, the main difference is:

- The server doesn’t manage the logic of “who is the next player in turn”

- The server doens’t distribute the received command via a GameActionProcessor

And another change: game action type is an int, now. In the previous release, it was an enum, reflecting a fixed set of action types.

It still updates the game status blob adding the new game command (it could be a chat message, or a new shot). In this new way, THE SERVER CODE is more independent from game logic: the client code has the responsibility of select the next player. The notion of turn is leave to game client development. Now, the server code could be used for other multi-players games. Yes, we could have our own Social game! ;-)

Windows Azure and worker/web roles are in charge of federated authentication, the formation of  new games, etc. But the engine is more “game agnostic” in this new release.

The client code sends commands:

Steps:

1- Client code sends a new Game Action in JSON (i.e.: shot information (position, angle, force)).

2- A web role instance receives the Game Action and updates the list of actions in the corresponding game blob status (saving the actions of the last 10 seconds)

3- The other players are polling the game status, until they notice a new game action that implies turn change.

Client code could manage the case of timeout of its player, or the “going offline” of one the other browsers.

Pros:

- Server code is more generic, and it could be used for other games

Cons:

- The client code could be cheated (no server control, validation over game actions)

- More complexity (turn logic, timeout management, offline and latency issues, cheat control) at client code.

The litmus test: implementing a new game using the same server code. Some points to polish: skirmish mode is still hardcoded to a maximum of 5 players; the 10 seconds windows for game actions is arbitrary. Possible solutions: each game client code creates a new game (waiting for other players) specifying the minimum, maximum number of players and a timeout in seconds, and time window for game action status.

But remember, the example code is still in beta. A new version is coming.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

July 29, 2011

Social Online Games Programming (Part 3) Tankster, Blob Storage and JSONP

Filed under: .NET, AJAX, ASP.NET MVC, Azure, Game Development, HTML5, JavaScript, JQuery — ajlopez @ 10:59 am

Previous Post
Next Post

In my previous post I wrote about the Windows Azure Social Gaming Toolkit, and its example multi-player online game Tankster. See:

http://watgames.codeplex.com/
http://www.tankster.net/

There are two interesting posts by @ntotten about the inner guts of the game:

Architecture of Tankster – Introduction to Game Play (Part 1)
Architecture of Tankster– Scale (Part 2)

It’s worth to mention Nathan’s text here:

Before we begin with an explanation of the implementation, it is important to know what our goals where for this game. We had three primary goals when building this game.

  1. The game must scale to handle several hundred thousand concurrent users.*
  2. The architecture must be cost effective.
  3. The architecture must be flexible enough for different types of games.

* This is the goal, but there are still some known limitations in the current version that would prevent this. I will be writing more about that later.

Now, I want to write about the use and implementation of blob storage in Tankster.

Why to use blob storage? If you play Tankster in practice mode, the Javascript client doesn’t use the Azure backend. Javascript can access web role and blob storage via Ajax/JSON calls. But in multi-player game (there is one kind of game, named Skirmish), each player client code polls the blob storage to get the game status (tank shots, chat messages, other status). But again, why blob storage? There are money reasons (cost of each access to Web Role service API vs. cost of read a blob), but I don’t know about Azure prices (you know, MVPs don’t touch the money ;-). But there is another reason: to spread the workload, given some air to web role instances.

There is an AzureBlobContainer class in Tankster.Common library project:

public class AzureBlobContainer<T> : IAzureBlobContainer<T>
{
    private readonly CloudBlobContainer container;
    private readonly bool jsonpSupport;
    private static JavaScriptSerializer serializer;
    public AzureBlobContainer(CloudStorageAccount account)
        : this(account, typeof(T).Name.ToLowerInvariant(), false)
    {
    }
    public AzureBlobContainer(CloudStorageAccount account, bool jsonpSupport)
        : this(account, typeof(T).Name.ToLowerInvariant(), false)
    {
    }
    public AzureBlobContainer(CloudStorageAccount account, string containerName)
        : this(account, containerName.ToLowerInvariant(), false)
    {
    }
	//....

 

The class use generics. Type T could be a Game, GameQueue or another .NET type. You can reuse this class in other projects: it’s “game agnostic” code. The many constructors add flexibility for testing purpose.

This is the code to save a typed object to a blob:

public void Save(string objId, T obj)
{
    CloudBlob blob = this.container.GetBlobReference(objId);
    blob.Properties.ContentType = "application/json";
    var serialized = string.Empty;
    serialized = serializer.Serialize(obj);
    if (this.jsonpSupport)
    {
		serialized = this.container.Name + "Callback(" + serialized + ")";
    }
    blob.UploadText(serialized);
}

The object (type T) is serialized to JSON. AND not only JSON: note that a there is a Callback (you could remove this part if you don’t need this feature in your project). Then, a game object is saved as (I stolen …errr… borrowed ;-) this code from Nathan’s post):

gamesCallback(
    {"Id":"620f6257-83e6-4fdc-99e3-3109718934a6"
    ,"CreationTime":"\/Date(1311617527935)\/"
    ,"Seed":1157059416
    ,"Status":0
    ,"Users":[
        {"UserId":"MxAb1iZtey732BGsWsoMcwx3JbklW1xSnsxJX9+KanI="
        ,"UserName":"MxAb1iZtey732BGsWsoMcwx3JbklW1xSnsxJX9+KanI="
        ,"Weapons":[]
        },
        {"UserId":"ZXjeyzvw7WTdP8/Uio4P6cDZ8jmKvCXCDp7JjWolAOY="
        ,"UserName":"ZXjeyzvw7WTdP8/Uio4P6cDZ8jmKvCXCDp7JjWolAOY="
        ,"Weapons":[]
        }]
    ,"ActiveUser":"MxAb1iZtey732BGsWsoMcwx3JbklW1xSnsxJX9+KanI="
    ,"GameRules":[]
    ,"GameActions":[]
    })

Why the callback? To support JSONP:

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

JSONP or “JSON with padding” is a complement to the base JSON data format, a pattern of usage that allows a page to request data from a server in a different domain. As a solution to this problem, JSONP is an alternative to a more recent method called Cross-Origin Resource Sharing.

Under the same origin policy, a web page served from server1.example.com cannot normally connect to or communicate with a server other than server1.example.com. An exception is the HTML <script> element. Taking advantage of the open policy for <script> elements, some pages use them to retrieve Javascript code that operates on dynamically-generated JSON-formatted data from other origins. This usage pattern is known as JSONP. Requests for JSONP retrieve not JSON, but arbitrary JavaScript code. They are evaluated by the JavaScript interpreter, not parsed by a JSON parser.

If you are a newbie to JSON and JSONP, this is a short tutorial/example using JQuery (the same library used by Tankster client code):

Cross-domain communications with JSONP, Part 1: Combine JSONP and jQuery to quickly build powerful mashup

But (you know, there is a “but” in every software project ;-) Azure blob storage doesn’t support the JSONP URL (that has a randomly generated callback id):

Query JSON data from Azure Blob Storage with jQuery

There is a proposed solution in that Stack Overflow thread. Agent Maxwell Smart would say: ah! the “old trick” of having the callback in the blob!

dataCallback({"Name":"Valeriano","Surname":"Tortola"})

You can read a more detailed description of problem/solution with example code at @woloski’s post (good practice Matthew! write a post!):

Ajax, Cross Domain, jQuery, WCF Web API or MVC, Windows Azure

One problem to point: note that the callback name is “hardcoded” in blob storage. The gamesCallback present in game status blob should be the name of a global function. But you can change the blob text to whatever valid Javascript code.

And the client code? You can study the gskinner code at Tankster.GamePlay web project, under src\ui\net\ServerDelegate.js:

(function (window) {
    goog.provide('net.ServerDelegate');
    goog.require('net.ServerRequest');

    var ServerDelegate = function () {
        throw new Error('ServerDelegate cannot be instantiated.');
    };

    var p = ServerDelegate;

    p.BASE_API_URL = "/";
    p.BASE_BLOB_URL = "http://tankster.blob.core.windows.net/";
    p.BASE_ASSETS_URL = "";
    p.load = function (type, data, loadNow) {
        var req;
        if (p.CLIENT_URL == null) {
            p.CLIENT_URL = window.location.toString();
        }
//....

There is an interesting switch:

switch (type) {
    //Local / config calls
    case 'strings':
        req = new ServerRequest('locale/en_US/strings.js',
		   null, 'jsonp', null, 'stringsCallback'); break;
    //Game calls
    case 'endTurn':
        req = new ServerRequest(apiURL+'Game/EndTurn/',
		    null, 'xml'); break;
    case 'leaveGame':
        req = new ServerRequest(apiURL+'Game/Leave/'+data.id,
		    {reason:data.reason}, 'xml', ServerRequest.POST); break;
    case 'playerDead':
        req = new ServerRequest(apiURL+'Game/PlayerDead/',
		    null, 'json'); break;
    case 'gameCreate':
        req = new ServerRequest(apiURL+'Game/Queue', data,
		    'xml', ServerRequest.POST); break;
    case 'usersGame':
        req = new ServerRequest(blobURL+'sessions/'+data,
		    null, 'jsonp', null, 'sessionsCallback'); break;
    case 'gameStatus':
        req = new ServerRequest(blobURL+'games/'+data,
		    null, 'jsonp', null, 'gamesCallback'); break;
    case 'gameQueueStatus':
        req = new ServerRequest(blobURL+'gamesqueues/'+data,
		    null, 'jsonp', null, 'gamesqueuesCallback'); break;
    case 'notifications':
        req = new ServerRequest(blobURL+'notifications/'+data,
		    null, 'jsonp'); break;

    //User calls
    case 'verifyUser':
//...

See the ‘gameStatus’ polling: it uses ‘jsonp’ as format. My guess: the ‘gamesCallback’ parameter is not needed: you can use any other name, the function to call resides in the blob content.

I think there are alternatives to game status. The blob reflects the Game entity (see Tankster.Core\Entities\Game.cs). But it could be implemented in two blobs by game:

- One, having the initial status (players, positions,etc…) and the list of ALL the history of the game (think about to implement a chess or go game, you need to save the history).

- Another one, having the “news” (last 10 seconds of game actions). So, the data to poll should be shorter.

The price to pay: web role service should update both. But that update only occurs when a player sends a move (shot, chat…). The poll of game status occurs in every client, triggered by a repeated timeout. Actually, the game blob keeps the last 10 seconds actions AND initial status, weapons, etc…. Each client polls that info. In case a client disconnects and reconnects, it could poll the “complete game” blob to be in sync again.

The separation of that info in two blobs should improve the scalability of the solution. But you know: premature optimization is the root of all evil ;-). If you take that way of store and retrieve games, you should run some stress or/and load tests to have a really measure of such decision impact.

More Tankster code analysis, patterns, and social game dev in general: coming soon.

Some links:

WAT is to Social Gaming, as Windows Azure is to… | Coding4Fun Blog | Channel 9

Thanks! They mention my post ;-)

Episode 52 – Tankster and the Windows Azure Toolkit for Social Games | Cloud Cover | Channel 9

Microsoft tailors Azure cloud services to social game developers | VentureBeat

Windows Azure Toolkit for Social Games Released to CodePlex – ‘Tankster’ Social Game Built for Windows Azure

Tankster, a Social Game Built for Windows Azure | Social Gaming on Windows Azure | Channel 9

Social Gaming on Windows Azure | Channel 9

Build Your next Game with the Windows Azure Toolkit for Social Games

Microsoft delivers early build of Windows Azure toolkit for social-game developers | ZDNet

http://www.delicious.com/ajlopez/tankster

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

Older Posts »

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

Follow

Get every new post delivered to your Inbox.

Join 57 other followers