Flash Multiplayer Virtual Worlds
上QQ阅读APP看书,第一时间看更新

Developing and deploying virtual world environment

SmartFoxServer works excellently as a socket server in connecting clients and provides multiplayer features to virtual world. However, we also need a web server and database set up in practical use.

It may be disorienting at the beginning that we are using three types of servers at the same time. The following graph shows how these servers are responsible for different roles. We need a web server to host the virtual world website and Flash SWF. We also need a database server to store all user information permanently.

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.

SmartFoxServer is also able to work together with third-party web servers and databases, for example, Apache and MySQL.

There are different situations on setting up the servers of Flash virtual world such as sometimes using SmartFoxServer with its embedded HTTP server and database while sometimes it is more beneficial to use SmartFoxServer with third-party servers.

Setting up a suitable sever environment before coding, on the other hand, enables us to have a plan and design of the whole architecture of the virtual world. It is a good practice to make a detailed plan before developing software, especially big scale software such as Flash virtual world.

We are going to compare the development environment and deployment environment, with different sever settings that may be applied.

Adjusting server setting for the deployment environment

In deployment of the virtual world, we have to choose the SmartFoxServer to fit the platform of the server instead of your own development machine. The SmartFoxServer may be a host in a standalone dedicated machine or a host within the same machine of the web server. There are many different combinations of setting up the servers and we will compare the common solutions.

Hosting SmartFoxServer, web server, and database in one server

For hosting a small-scale or mid-scale virtual world, hosting all severs in the same machine will be a good choice. In this case, there is not much difference between using the embedded web and database server, or using a third-party one. The following figure shows host SmartFoxServer, web server, and database in one machine:

Hosting SmartFoxServer in dedicated standalone server

For hosting a big scale virtual world, it is good to host the SmartFoxServer in a standalone machine. This machine can virtually be a Virtual Private Server or physically a dedicated machine. More SmartFoxServer performance and scaling information can be found in the official SmartFoxServer documentation (http://www.smartfoxserver.com/whitepapers/performance/index.html). The following figure shows host SmartFoxServer in standalone:

As the web server and database are not in the same machine of the SmartFoxServer, the choice of the web server and database is open. The web server can be Jetty, Apache, or others. The database server can be MySQL, Oracle, or any other available database server.

Benefiting from setting up SmartFoxServer, web server, and database in different machines

These servers are targeting different purposes and tasks. Each of them has a different requirement for server specification. Therefore, they are often put into different machines so that each machine can have the performance tuned to fit each server's purposes best.

Another benefit of putting them into different machines is that it enables centralized managed database storage. It is common in game industry that you log in to different online games or virtual worlds with one user account. After your virtual world has grown, you will probably have more than one server instance running the virtual world server. You may even have grown into to hosting several virtual worlds in several servers. The players will then query and authenticate from a standalone centralized database and then use that information to join different virtual worlds. The following diagram shows a host multi-virtual world server with the same database:

Setting up the development environment

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. However, we will go through both solutions and focus on SmartFoxServer with a third-party web server and database combination.

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.