Mongoose for Unity

Mongoose is a C library for embedding a simple web server in another application. We used Mongoose for all of our web-enabled Torque games and I wanted to be able to continue using it for new games in Unity.

There is an existing extension called UniWeb which provides a web server in unity, but their code doesn’t support web sockets. I’ve just built Mongoose in windows, but it is Linux and Mac compatible as well. However, it wont support any of the mobile platforms.

This post will describe the steps for building Mongoose 5.6 as a windows native DLL, then wrapping it for use in C#, and finally including it in a Unity project.

Continue reading “Mongoose for Unity”

Web controls for Fire Platoon

We have decided to move the player controls off the touch table and onto individual web-enabled devices in Fire Platoon. There are a couple reasons for this decision. Most importantly, we didn’t have enough space to put even four player’s controls onto the screen and still have legible icons on the main map of the building. Second, we think that players will feel more connected to their in-game fire fighter if they are holding the controls in their hands. With off-screen controls, we can make the game map bigger and support more players (probably 8)

We are going to use web sockets to send messages between the game and the player’s web clients. Web sockets are now supported by all the web browsers, so anyone with a smartphone or tablet should be able to connect to the game and play without downloading an app. Continue reading “Web controls for Fire Platoon”

Web sockets and Mongoose

A couple of weeks ago, I experimented with using bluetooth to communicate hidden information from a game to a phone held by the players. While the prototype worked, there were issues with client side logic and lack of support for iOS.

Another way to achive the goal of displaying hidden information on the phone would be to create a web page that the phone could access. In the past, we have done this by having the game state in a MySQL database and php scripts to access the data. The game server and clients would poll the data watching for updates and sending their moves. This system was cumbersome, laggy and prone to error.

However, the web page is a nice way to provide the data to the clients. It is easy to layout a good looking interface, you can use javascript to allow the player to interact with the game and all phones have a web browser. The problem lies in the communication back to the C++ game.

One solution to this problem would be to use web sockets to send data back and forth between the clients and the game. Ideally, the C++ game would serve out the web pages that the clients display too so that people buying the game wouldn’t have to know how to setup a web server.

Mongoose is a simple web server with web socket support that can be compiled into a C++ application. With a couple of minor tweaks I got the mongoose code integrated into Torque.

Adding web sockets was a bit more problematic. The support for raw web socket connections comes with Mongoose, but I needed to write the code to send and receive the messages in the format expected by the chrome WebSocket class.

Continue reading “Web sockets and Mongoose”