(For more resources on Flash, see here.)
We are going to download and install Apache and MySQL server package. These kinds of server package features have easy install that auto-configures most of the server settings. It will also install some essential tool for beginners to manage the server easily, such as GUI server administration panel.
WampServer is an open source HTTP and database server solution on Windows. WAMP stands for Windows, Apache, MySQL, and PHP package.
The WampServer can run by launching from Start | Programs | WampServer | Start WampServer.
It will be in the task bar and the server management operation can be found by clicking the WampServer icon. We can start the server by putting the server online in the menu.
Similar to WampServer, MAMP is the one package web server solution that stands for Mac, Apache, MySQL, and PHP package. The MAMP package can be downloaded at http://www.mamp.info/.
To run the MAMP server, go to Applications | MAMP and double-click on the MAMP.app.
As the same naming convention, the "L" stands for Linux here. Different Linux distributions use different ways to install applications. There may not be a oneclick install method on some Linux branch which requires us to install the Apache and MySQL individually. Some Linux may provide graphic user interface to install LAMP by just selecting it in the applications list. We will use Ubuntu to demonstrate the installation of LAMP.
sudo tasksel install lamp-server
After the completion of the installation, the MySQL server is set up as service in the system. It runs automatically and we do not need to manually launch it to use it.
SmartFoxServer is a Java application and Java database connection driver is needed to connect from SmartFoxServer to MySQL database.
JDBC is a Java database connection driver that we need to establish connections between the Java-based SmartFoxServer and the MySQL server. The JDBC driver for MySQL is called Connector/J. We are going to install it to enable MySQL connection from SmartFoxServer.
The MySQL Java connector comes with a bunch of files. We only need two among them.
The configuration file of SmartFoxServer is an XML file that allows us to configure many server settings. It can configure the initial zone or room creation, server address, admin authorization, value tuning for performance, and a lot more. We are going to set the database connection for testing our setup in this article (core settings are out of scope of this article).
The configuration file is called config.xml and is located in the SmartFoxServer installation directory under the Server directory.
<DatabaseManager active="false">
<Driver>sun.jdbc.odbc.JdbcOdbcDriver</Driver>
<ConnectionString>jdbc:odbc:sfsTest</ConnectionString>
<!--
Example connecting to MySQL
<Driver>org.gjt.mm.mysql.Driver</Driver>
<ConnectionString>jdbc:mysql://192.168.0.1:3306/sfsTest
</ConnectionString>
-->
<UserName>yourname</UserName>
<Password>yourpassword</Password>
<TestSQL><![CDATA[SELECT COUNT(*) FROM contacts]]></TestSQL>
<DatabaseManager active="true">
<Driver>org.gjt.mm.mysql.Driver</Driver>
<ConnectionString>jdbc:mysql://127.0.0.1:3306/mysql
</ConnectionString>
<UserName>root</UserName>
<Password></Password>
<TestSQL><![CDATA[SELECT NOW()]]></TestSQL>
The new setting activates the DatabaseManager and configures the JDBC driver to the MySQL connector that we just downloaded.
We also changed the user name and password of the connection to the database to "root" and empty password.
We will use the empty password through out the development process but it is strongly recommended to set your own database user password.
There is a TestSQL setting where we can write a simple database query so that the SmartFoxServer will try to run it to test if the database connection is correct. As we have not created any new databases for the virtual world, we will test the database connection by querying the current server time.
We’ve just set up the connection between SmartFoxServer and third-party database. It is time to test the new setting by restarting the SmartFoxServer.
To stop the SmartFoxServer in Windows and Linux, press Ctrl + C. To stop it in Mac OS X, click on the Cancel button in the SmartFoxServer log window.
There is a log that appears as usual after we start up the server again. It is important to check the log carefully every time the config.xml is changed. The logfile can provide details of any errors that occur when it tries to load the configure file.
For example, if we configure the database connection just now but forget to activate the DatabaseManager, the server will start up correctly. Then you may spend a lot of time debugging why the database connection is not working until you find that the DatabaseManager is not active at all. This happened to me several times while I was developing my first flash virtual world.
If the server is running with the new database connection settings, the following lines will be appearing in the log. There can be different database manager settings for each zone. When checking the log, we should be aware which zone the log is referring to. We are configuring the database manager of dbZone zone now.
DB Manager Activated ( org.gjt.mm.mysql.Driver )
Zone: dbZone
If we forget to activate the DatabaseManager, we will not see the DB Manager Activated wording. Instead, the following message may appear in the log:
DB Manager is not active in this Zone!
Moreover, if the SmartFoxServer faces some fatal error on start up, it will terminate itself with more detailed error logs. The following lines are an example for error logs that appear when the MySQL connector file is missing:
Can’t load db driver: org.gjt.mm.mysql.Driver
[ Servre ] > DbManager could not retrive a connection. Java.sql.SQLException: Configuration file not found
DbManagerException: The Test SQL statement failed! Please check your configuration.
These lines state that the testing SQL failed to run, which we just set to test the connection. It also describes what exception has caused this error to help the debugging.