Saying “Hello World”

So let’s dive in and start coding!

We’re assuming you’ve installed Visual Studio 2012 and the latest Casablanca SDK. We’re using the bits published on Sep 24.

The code for this project is available at in the ‘HelloWorld’ directory.

This code is quite different from the default we talked about in the video, and reflects the evolution and maturing of the Casablanca SDK itself. In fact, the next version of the Casablanca SDK may have a different default application, reflecting further improvements in the SDK. We’ll do our best to keep the blog up-to-date!

Fire up Visual Studio and create a new Casablanca project…


[The older bits gave us a second dialog allowing us to choose a Web or Worker role, and configure those appropriately, but the current drop seems to blitz past that dialog. I will post an explanation as soon as I find one! –John]

…which gives us the default project.


We’ll walk through the code in a minute, but let’s run the project as is, and see what happens…


Boom! The code compiles and runs, but obviously fails. It is time to dissect the code and understand what’s going on inside.

Let’s look at the project first, and figure out what is going on there:

First of all, the C++ compiler needs to get some header information about the Casablanca classes…


…and the linker needs to include the Casablanca libraries…


Pay close attention to the SDK folder, as this may change with future releases, and you will need to update your projects as and when this happens.

[I don’t know if there is a system like ‘nuget’ or ‘apm’ for Visual C++ projects, which can consume a library and keep it up-to-date in a streamlined way. It sure sounds like a good way to release Casablanca bits –John]

The actual Casablanca library is dependent on the version of Visual Studio. For VS 11 aka VS 2012, it is called ‘casablanca110.lib’. The Actors library, analogously, is contained in ‘actors110.lib’. This will be different if you’re using VS 2010.


Similarly, the Project Configuration has a reference to a Platform Toolset, which is how the project is configured to build in a given version of Visual Studio.


The project we are building does not create an .exe file. Rather, we are writing a library, as highlighted above. Our DLL is loaded by a host which is part of the Casablanca system. When we run the project in Visual Studio 2012, we are actually running CasablancaHost110.exe, and specifying the DLL to load in the actors_config.cfg file.



Therefore, there is a Post-Build step to copy it from the project directory to the deployment target directory.


Now let’s go and get the application running:

The only material change that is required is that the endpoint needs to be specified. We could change

// Function to help find dynamically assigned port for our endpoint.
casablanca::string_t find_addr(const std::vector<casablanca::string_t> &configs)
    // The configuration data is a vector of [key1,value1,key2,value2,...,keyN,valueN] pairs.
    return U("http://*");


// Function to help find dynamically assigned port for our endpoint.
casablanca::string_t find_addr(const std::vector<casablanca::string_t> &configs)
    // The configuration data is a vector of [key1,value1,key2,value2,...,keyN,valueN] pairs.
    return U("http://localhost:8181");

and run successfully.


The functionality we’re demonstrating above is provided by the handler for the HTTP GET verb. We’re specifying that here., [](http_request message)
        message.reply(http::status_codes::OK, U("Hello World!"));
        actors::log::post(actors::LOG_INFO, U("Serviced a GET request for ") + message.request_uri().to_string());

What we are actually doing is providing the listener a call-back lambda which writes “Hello World” into the response of the current request.

Two key points for the future:

1) This lambda does not close over any local or instance variables, so it’s effectively a free-standing static method. We can use this information to build more complex mechanisms to respond to HTTP methods in the future

2) There are several overloads to message.reply(), and we’ll encounter a few more as we build other projects.

That’s it for now. I hope this post has provided a detailed explanation of the basic infrastructure of a Casablanca project, which helps you to understand what is going on better!

Happy Coding!


Leave a Reply

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

You are commenting using your 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