Hello pomelo, pomelo
This article describes how to start a simple demo of pomelo.
1. Create a pomelo project named helloworld.
Use the command line to create a project. Pay attention to the location of the current folder. The helloWorld is under the current folder. There is no difference between win and mac.
pomelo init ./HelloWorld
For more pomelo command lines, refer to here
When initializing a project, you need to select the communication protocol used at the underlying layer, including socket. io and websocket.
2. Go to the HelloWorld folder and install the dependency package.
Mac/linux
sh npm-install.sh
Win
npm-install.bat
3. directory structure
The directory structure clearly shows the front-end and back-end layered structure of the game project, and fill in the relevant code under each directory to quickly develop the game. The following is a brief analysis of each directory:
Game-server
Game-server is a game server built with the pomelo framework. It uses file app. js as the portal to run all the logic and functions of the game. In the subsequent development, all game logic, functions, and configurations are carried out in this directory.
App subdirectory
All game server codes are stored in this directory. Users can implement different types of servers and add corresponding Handler and Remote servers.
Config subdirectory
The config in game-server contains all the configuration information of the game server. The configuration information is defined in the format of a JSON file, including the configuration information of the log, master, server, and other servers. This directory can also be expanded to define database configuration information, MAP information, numeric table and other information. All in all, this is where configuration information related to all game servers is stored.
Logs subdirectory
Logs are indispensable in the project. They can be used to back up the running status of the project and serve as a reference for system O & M. logs stores all the log information of the game server.
Shared
Shared stores some front-end and back-end, game-server and web-server code. Because they are all javascript code, some tools or algorithm code can be shared between front-end and back-end, this greatly improves code reusability.
Web-server
Web-server is a web server built using the express framework. It uses file app. js as the portal. Of course, developers can choose other web servers such as Nginx. If the game client is not web, such as the Android platform, this directory is not required. Of course, in this example, our client is web, so the web server is required.
4. Start the project
In this example, because the client is web, you must start game-server and web-server)
Start the game-server:
cd game-serverpomelo start
Start the web-server:
cd web-servernode app
If it fails to be started, the previous step may fail to be installed. you can install it again.
After the web-server is started successfully, you will be prompted to access the 127.0.0.1: 3010 page to access the server.