Flash Multiplayer Virtual World with SmartFoxServer Using Embedded Web Server and Database

Exclusive offer: get 50% off this eBook here
Flash Multiplayer Virtual Worlds

Flash Multiplayer Virtual Worlds — Save 50%

Build immersive, full-featured interactive worlds for games, online communities, and more

$29.99    $15.00
by Makzan | August 2010 | Web Graphics & Video

SmartFoxServer comes with an embedded HTTP server (Jetty), which can handle web pages and a light-weight database engine (H2). Using the embedded HTTP server and database can enable a rapid prototype development because we can start coding the Flash prototype of the ideas in mind without handling any server setup issues.

In this article by Makzan, author of Flash Multiplayer Virtual Worlds, we will cover:

  • Installing Java Development Kit
  • Downloading and Installing SmartFoxServer Pro
  • Running the SmartFoxServer
  • Using embedded web server and database

(For more resources on Flash, see here.)

Unlike a deployment environment, it is common to have just once machine acting both as server and client in a development environment. The machine will have SmartFoxServer, web server, and database installed. In this case, there are no noticeable differences between using the embedded or third-party web server and database.

It is a good habit to simulate the deployment environment as much as possible in development stage. As we are going to use a third-party web server and database, we will set up a development environment that also uses the third-party server instead of the embedded web server and database in the third part of this article series.

Installing Java Development Kit

The Java Development Kit includes the essential development tools (JDK) and the Java Runtime Environment (JRE). The development tool compiles the Java source code into byte codes and the JRE is the response to execute the byte codes. We will need several Java compilations in later chapters. SmartFoxServer is build on the Java environment and we need the JRE to start up the server. The JDK and JRE may be pre-installed in some OSs.

Installing JDK On Windows

The steps for installing JDK on Windows are as follows:

  1. Go to http://java.sun.com/javase/downloads/.
  2. Click on the Download button of Java. It will lead to the Java SE Downloads page.

  3. Select Windows (or Windows x64 for 64-bits Windows) in Platform.
  4. Click on Download.
  5. If it prompts an optional login request, we can click the Skip this Step to bypass it.
  6. Launch the installer after the download.
  7. Install the Java Development Kit with all default settings.
  8. The Java environment is ready after installation completes.

Installing JDK on Mac OSX

The Mac OSX comes with its own set of Java environment. We can check the JDK and JRE version by following steps:

  1. Launch terminal from Applications | Utilities | Terminal.
  2. Type the following and press the Enter key:

    javac -version

  3. The command will output the currently installed version of the Java in the Mac OSX. In my case, it outputs: javac 1.6.0_17.

The current version of SmartFoxServer at the time of writing recommends the version 1.6. If the Java is not updated, we can update it via Apple Menu | Software Update.

The software update will check for any updates for your existing Mac software, including the Java environment.

Installing JDK on Linux

We can use the general method to download and install the JDK or use the system specific method to install the package. We will show the general method and the Ubuntu method.

Installing for General Linux

  1. Go to http://java.sun.com/javase/downloads/index.jsp in browser.
  2. Click on the Download button.
  3. The platform Linux should be selected automatically. Otherwise, select Linux (or Linux x64 for 64-bit Linux).
  4. Click on Continue.
  5. If it prompts for login, click on Skip this Step to bypass it.
  6. For Redhat or Fedora Linux, choose the rpm-bin file to download. For other Linux, choose the .bin file to download.
  7. Launch terminal via Applications | Accessories | Terminal after the download completes.
  8. Change the directory to the folder that contains the downloaded package. The download destination varies from different profile settings. In my case, it is in Downloads folder.

    cd ~/Downloads/

  9. The version is Java 6 Update 20 at the time of writing and the filename is jdk-6u20-linux-i586.bin or jdk-6u20-linux-i586-rpm.bin.
  10. Then we make it executable and launch the installer by the following commands:

    chmod a+x jdk-6u20-linux-i586.bin

    ./jdk-6u20-linux-i586.bin

  11. The installer displays the license agreement. Type Yes at the end to agree and continue installation.
  12. Press the Enter key after the file’s extraction to end the installation.

Installing for Ubuntu Linux

Ubuntu users can install the JDK via the apt-get command.

  1. We will search for the latest package name of the JDK by the following command:

    apt-cache search --names-only sun-java.*-jdk

  2. The result shows the available JDK packet names. At the time of writing, it is JDK6:

    sun-java6-jdk - Sun Java(TM) Development Kit (JDK) 6

  3. We use the apt-get command to install the JDK:

    sudo apt-get install sun-java6-jdk

  4. Type in the user password because it requires user’s password and the privilege to use apt-get.
Flash Multiplayer Virtual Worlds Build immersive, full-featured interactive worlds for games, online communities, and more
Published: August 2010
eBook Price: $29.99
Book Price: $49.99
See more
Select your format and quantity:

(For more resources on Flash, see here.)

Downloading SmartFoxServer Pro

We are going to walkthrough the installation of SmartFoxServer Pro and third-party web server and database in all supported platforms.

For Windows, Mac OS, and Linux that have a graphic user interface, you can follow these steps to download the SmartFoxServer Pro:

  1. Go to http://www.smartfoxserver.com/products/pro.php#downloads in web browser.
  2. Select the OS platform. We will use Windows 32-bit as an example here.
  3. The download will start after clicking on the Download button.

For Linux platform that does not have a graphic user interface, you can follow these steps to download the SmartFoxServer Pro Linux x86-32-bit version:

  1. Go to the directory that planned to place the SmartFoxServer.
  2. Type the following line in the terminal to download the file:

    wget http://www.smartfoxserver.com/products/download.php?d=76

  3. The download will start after pressing the Enter key.

For a Linux platform that does not have graphic user interface, you can follow these steps to download the SmartFoxServer Pro Linux x86-64-bit version:

  1. Go to the directory that planned to place the SmartFoxServer.
  2. Type the following line in the terminal to download the file:

    wget http://www.smartfoxserver.com/products/download.php?d=77

  3. The download will start after pressing the Enter key.

Installing SmartFoxServer Pro

The installation process is different from SmartFoxServer for Windows, Linux, and Mac OS.

Installing on Windows

  1. Run the installer SFSPRO_win_1.6.6.exe.
  2. When asked for the installation path we change the install path to any directory under the user folder, such as C:\Users\username\SmartFoxServerPRO_1.6.6.

We change the installation path instead of the default path under Program Files because latest Windows requires administrator privileges to change the files.

Installing on Mac OSX

  1. After downloading the SmartFoxServer, it will be automatically mounted.
  2. Open the Applications folder.
  3. Drag the SmartFoxServer Pro 1.6.6 folder into Applications.

Installing on Linux

  1. Launch the terminal from Applications | Accessories | Terminal.
  2. Go to the enclosing folder of the SFSPRO_linux_1.6.6.tar.gz.
  3. Type following command in the terminal to decompress the tar:

    tar zxf SFSPRO_linux_1.6.6.tar.gz

Running the SmartFoxServer

There are different ways to run the SmartFoxServer in different platforms.

Starting SmartFoxServer on Windows

The SmartFoxServer can be launched from the start menu. Click on Start | Programs | SmartFoxServerPro_1.6.6 | Start SmartFoxServer.

A command prompt will then appear and it shows up logs of loading different modules. Error messages may appear if there is any error that fails to start up the server.

Starting SmartFoxServer on Mac OS

The server launcher is located in Applications | SmartFoxServer Pro 1.6.6 | SmartFoxServer.app. Double-click to launch it and it will also display the log in a window.

Starting SmartFoxServer on Linux

  1. Launch terminal from Applications | Accessories | Terminal.
  2. Go to the SmartFoxServer installation folder | Server.
  3. Type the following command in the terminal to launch the server:

    ./start.sh

Using embedded web server and database

We are going to play with the embedded web server and database. The embedded web server and database are well-configured and run on startup by default. This lets developers rapidly develop the prototype of the virtual world without worrying about setting up different servers.

Running the embedded web server

By default, the web server is running on port 8080 with same SmartFoxServer location.

After starting up the SmartFoxServer, go to http://localhost:8080 in the web browser. If a webpage shows up with a message "SmartFoxServer Pro 1.6.6 is installed successfully", it means the server is working with default settings.

The HTTP documents directory of the embedded server is located in Installation folder | Server | webserver | webapps | root. You can modify and store static web pages within this folder to host the virtual world website.

Running the embedded database server

The embedded H2 database server is well-configured upon SmartFoxServer installation.

Windows users can launch the H2 Database Admin Tool by double-clicking the adminDB.bat, which is located in SmartFoxServer installation directory | Server. Linux and Mac users can launch by executing the following command in the terminal in the Server directory:

chmod +x adminDB.sh

./adminDB.sh

After executing the adminDB script, a web interface of the Admin tool will open in browser.

We will use the default saved settings to connect the H2 database. In Windows and Linux, the default setting is Generic H2, while in Mac, the setting is called Generic H2 (Embedded).

If the development is based on H2 Database engine, we can test the database by clicking the Connect button with default settings.

After connected to the H2 database engine, the admin panel is divided into three parts. The upper part contains action buttons for operating the database such as the logout or execute commands. The left part lists all available users and tables. The right part is for inputting the SQL commands and viewing the results. H2 database is a light-weight engine that we need to operate the database by typing all the SQL commands ourselves.

Summary

In this article we covered running SmartFoxServer using embedded web server and database. In ths next article we will deal with SmartFoxServer together with third-party web servers and databases, for example, Apache and MySQL.

 


Further resources on this subject:


Flash Multiplayer Virtual Worlds Build immersive, full-featured interactive worlds for games, online communities, and more
Published: August 2010
eBook Price: $29.99
Book Price: $49.99
See more
Select your format and quantity:

About the Author :


Makzan

Makzan is the founder of 42games limited (http://42games.net). He began building apps and games on the Web when he was a child. He built iOS games that have ranked No.1 on the App Store as well as demos on the Apple store. He now focuses on teaching programming.

Makzan has also written two books named Flash Multiplayer Virtual World and HTML5 Games Development Beginner’s Guide.

I would like to thank the whole team from Packt Publishing. The video series will not be possible without the help from all the editors. I thank all reviewers for providing very useful comments from which I have learnt a lot. I thank my family for giving me support during the process.

Books From Packt


Flash 10 Multiplayer Game Essentials
Flash 10 Multiplayer Game Essentials

Unity Game Development Essentials
Unity Game Development Essentials

3D Game Development with Microsoft Silverlight 3: Beginner's Guide
3D Game Development with Microsoft Silverlight 3: Beginner's Guide

wxPython 2.8 Application Development Cookbook: RAW
wxPython 2.8 Application Development Cookbook: RAW

Flash with Drupal
Flash with Drupal

WordPress and Flash 10x Cookbook
WordPress and Flash 10x Cookbook

Joomla! with Flash
Joomla! with Flash

Scratch 1.4: Beginner’s Guide
Scratch 1.4: Beginner’s Guide


No votes yet

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Y
V
6
r
L
d
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software