Developing TicToe HTML5/Preparing the Server
Development log of TicToe HTML5
Now it is time to get a basic (empty) server up and running.
server.ini
Marauroa is configured using a server.ini file. It tells the framework, how it can access its database and contains further information about the game. For now, just copy and paste the following code and save it as server.ini in your project root folder.
# Configure database using the serverless H2 engine
database_adapter=marauroa.server.db.adapter.H2DatabaseAdapter
jdbc_url=jdbc:h2:~/tictoe/database/h2db;AUTO_RECONNECT=TRUE;DB_CLOSE_ON_EXIT=FALSE
jdbc_class=org.h2.Driver
# TCP port for traditional clients
tcp_port=32170
# Web port
http_port=8080
# The length of the server game loop in milliseconds
turn_length=300
# Name of our game
server_typeGame=tictoe
server_name=TicToe
HTML5 just use https for secure communications and that is handled by the webserver. But for traditional clients, Marauroa has to do the encryption. Therefore we need to generate a key pair with the command: marauroa.tools.GenerateKeys
. It will ask for the key length and then output 3 lines that we append to the server.ini.
# Encryption key
n = 900370704947823124855781868486098993883139326458426419821694524929194085970977109550540519463413920574303896162026330535842004647058075091756193089826466644581
e = 15
d = 120049427326376416647437582464813199184418576861123522642892603323892544796130273271757994671295519024634180073146730306761515863656819847545998907329992154007
Important: Do not use these example keys but create your own pair.
Starting the server
Make sure that marauroa.jar, and its dependencies are on the classpath. Then execute the class marauroa.server.net.web.WebSocketServer
.
If all goes well, you will be greeted by some status message. The last one will be:
INFO [main ] marauroad (123 ) - marauroa is up and running... (startup time: 3.1 s)
Testing client/server communication
To test the setup, we open a web browser at http://localhost:8080/index.html.
This will just result in a green screen, but we can manually connect to the server by using the Firebug console. There is an input field at the bottom, that allows you to call any defined method and to inspect any object.
First of all, we need to connect to the server. Type this command and wait for the message "connected" in the console log:
marauroa.clientFramework.connect(null, null);
connected
While it is possible to execute more methods here, this is not useful because we have not implemented any server code, yet.