Game server framework ioGame 17.1.54 nginx proxy webSocket to get real ip

major update

[ #174 ] Fix the problem that when the action is handed over to the container management, it is instantiated twice

Obtain the data and extension of the external server of the game , and obtain the ResponseCollectExternalMessage. Add the optionalAnySuccess method to facilitate the successful optional

     public  String  getUserIp () { 
 ​ResponseCollectExternalMessage 
 message = ... ​return message                 . optionalAnySuccess () // get the return value                 . map ( ResponseCollectExternalItemMessage :: getData ) // will be String                 . map ( Objects :: toString ) // if not If an empty string is obtained, the caller does not need to make a null judgment.                 .orElse ( "" ) ;     }          
 
          
 
                 
 
                 
 
                 
 
 

 

Pressure test & simulation client request module, add module name identification

 public class BagInputCommandRegion extends AbstractInputCommandRegion {
     @Override
     public void initInputCommand() {
         this.inputCommandCreate.cmd = BagCmd.cmd;
         this.inputCommandCreate.cmdName = "背包模块";
     }
 }

 

Added HttpRealIpHandler to the external server of the new game , which is used to obtain the player's real ip support

The game uses the nginx proxy for the external server webSocket, which can also obtain the real player ip

 

The relatively friendly part of the framework is that if you use the nginx proxy, the player's ip will be resolved through HttpRealIpHandler, otherwise the ip of the netty channel will be used. Simply put, you can always get a player ip

 public  class  MyExternalServer { 
     ... ... omit part of the code 
 public ExternalServer createExternalServer ( int externalPort ) {         ... ... omit part of the code // Game External Server - Builder DefaultExternalServerBuilder builder = ... ​builder . setting () .setMicroBootstrapFlow ( new WebSocketMicroBootstrapFlow () { @Override protected void httpHandler ( PipelineContext context ) { super .       
 
         
           
 
          
             
                
                 httpHandler ( context ); 
 /* * HttpRealIpHandler is a handler built into the framework. * After adding it, you can get the real ip of the player even if it is forwarded through nginx */ context . addLast ( "HttpRealIpHandler" , new HttpRealIpHandler ());             }         }); ​// Build the game external server https://www .yuque.com/iohao/game/ea6geg return builder . build ();     } }                
                  
                  
                  
                  
 
 
 
         
          
 
 

 

 

ioGame usage trend statistics

The number of game server developers who pay attention to ioGame continues to increase, statistics from 2022-09 ~ 2023-08 ; 

The statistical information here is about developers paying attention to the ioGame framework. It can be seen from the statistical data that ioGame has attracted the attention of many developers due to its advantages such as easy to use and powerful functions. If you want to know if anyone is using ioGame, you can go here to read statistics, developer reviews and discussions.

https://www.yuque.com/iohao/game/gpxk93#TwVa8

The monthly statistical data is shown here. The statistical data comes from the background of Yuque. These data are real, objective and live .

Because of the cost, there is no merchant that can provide this kind of service in Mobao Mooduo, so such statistics are more authentic.

Through statistics, we can see that many developers visit ioGame's online documents every day, and these statistics are not derived from Kouhe, nor are they created subjectively.

Therefore, developers who are still hesitating whether to use ioGame should discuss "why these developers choose to use ioGame", rather than whether anyone is using ioGame.

Click me to view the data of ioGame in the background of Yuque

maven assistant

ioGame has been uploaded to the central warehouse. If the latest framework source code cannot be downloaded, it is recommended that the developer's maven warehouse proxy use the native or Tencent Cloud proxy. Alibaba Cloud's proxy is not currently recommended. For Tencent Cloud proxy settings, please refer to here .

Check the latest version of ioGame at  https://www.yuque.com/iohao/game/ab15oe

ioGame is a lightweight online game server framework. ioGame has no strong dependencies on middleware, that is, there is no need to install any other middleware products; at this time, you only need one dependency to get the entire framework, and at the same time support all functional characteristics.

<dependency>
    <groupId>com.iohao.game</groupId>
    <artifactId>run-one-netty</artifactId>
    <version>${ioGame.version}</version>
</dependency>

Overall frame preview map

 


Introduction to ioGame Network Game Server Framework

  • Lock-free asynchronous, event-driven architecture design; lightweight, without relying on any third-party middleware or database to support clustering, distributed
  • Through ioGame, it is easy to build a step-by-step game server with no central node in the cluster, cluster automation, and multi-process
  • Small package, fast startup, less memory usage, more economical, no need for configuration files, and provides elegant routing access control
  • Let developers use a set of business code without modification, and support multiple connection methods: WebSocket, TCP, UDP
  • Let developers use a set of business codes to easily switch and expand different communication protocols: Protobuf, JSON
  • Near-native performance; the business framework can execute an average of 11.52 million times of business logic per second in a single thread
  • Code is joint debugging document, JSR380 verification, assertion + exception mechanism = less maintenance cost
  • The framework has intelligent affinity with the same process; during development, business code can be located and jumped
  • Architecture deployment flexibility and diversity: both independent and integrated
  • Can communicate with multiple game logic servers of the same type at the same time and get data
  • Logic servers can communicate with each other across processes and machines
  • Support players to dynamically bind the game logic server
  • Compatible with any other framework
  • Friendly to webMVC developers
  • No spring strong dependency
  • Zero learning cost

 

Do you want to develop a step-by-step online game with high performance, stability, ease of use, built-in load balancing, avoiding class explosion design, cross-process cross-machine communication, cluster without central node, cluster automation, and stateful multi-process What about the server? If so, here I recommend you an online game server framework ioGame written in java language. The following will give a brief introduction to the framework from various aspects.

ioGame is a java online game server framework with the following features:

  • Lock-free asynchronous, event-driven architecture design
  • Support websocket and socket two communication protocols
  • Support different communication protocols such as protobuf and json
  • Cluster without central node, cluster automation, distributed design
  • Really lightweight, it can support cluster and distributed without relying on any third-party middleware or database
  • Provide multiple communication methods, and logic servers can communicate with each other across machines
  • Easy integration with spring and other frameworks
  • Low learning cost and good development experience
  • Support multi-server single-process, multi-server and multi-process startup and deployment methods
  • Provides accessibility features for game documentation generation
  • Small package size, fast startup, and low memory usage
  • Provide elegant routing access control
  • Provides flexible thread extension and settings
  • Smart same-process affinity

ioGame is a lightweight framework specially designed for online game servers , which can help you quickly build and run your own game servers. It is suitable for online games of all types and sizes, whether it is H5, mobile games or PC games, whether it is a simple chat room or a complex global server , turn-based games, strategy games, idle casual games, real-time battles, MMORPG, etc., ioGame can meet your needs.

ioGame is also excellent in terms of packaging, memory usage, and startup speed. After the jar package is about  15MB , the application usually  starts within 0.x seconds , and the memory footprint is small. For details, please see  the complete example of quickly writing a server from scratch .

In terms of ecological integration, ioGame can be easily integrated with spring (5 lines of code); in addition to spring, it can also be integrated with any other framework , such as: solon  ... etc., so as to use the relevant ecology of other frameworks.

In terms of lightweight, ioGame  can support clustering and distribution without relying on any third-party middleware or database , and only needs a java environment to run. This means that it is easy to use, and it also reduces deployment costs and maintenance difficulties for enterprises in terms of deployment. When using ioGame, you only need one dependency to get the whole framework without installing other services, such as: Nginx, Redis, MQ, Mysql, ZooKeeper, Protobuf protocol compilation tool...etc.

In terms of communication methods, most frameworks can only support push (broadcast) communication methods; while ioGame provides 5 types of communication methods, namely single request processing, push, and mutual communication between a single logical server , Communicate with multiple logic servers of the same type, and communicate in pulses . Through the combined use of various communication methods, the work that was difficult to complete in the past can be easily completed, and these communication methods support cross-process and cross-machine communication.

In terms of connection methods, ioGame allows developers to use a set of business codes while supporting multiple connection methods without any modification. ioGame already supports TCP, WebSocket and UDP connection methods, and also supports flexible switching between these connection methods. The connection method is scalable, and the expansion operation is also very simple, which means that if KCP is supported later, no matter whether your current project uses TCP, WebSocket or UDP, you can switch to KCP; note that even if you switch to KCP The connection method does not need to change the existing business code.

In terms of communication protocols, ioGame allows developers to easily switch and expand different communication protocols , such as Protobuf and JSON, with a set of business codes . Switch from Protobuf to JSON with just one line of code, without changing business methods.

In terms of clusters, ioGame's Broker (game gateway) adopts a central node-free, automated cluster design, all nodes are equal and autonomous, and there is no single point of failure. The cluster can be automatically managed and elastically scaled . When a node joins or exits, it can automatically ensure load balancing and data consistency without affecting service availability.

In terms of distribution, ioGame's logic server uses a distributed design idea, dividing the server into different levels such as game external server and game logic server, and each layer has clear responsibilities and interfaces. This improves code readability and maintainability, and facilitates horizontal expansion .

In terms of learning cost, the learning cost of ioGame is very low, it can be said to be zero learning cost , even if you have no game programming experience, you can easily get started. Developers only need to master ordinary java methods or webMVC-related knowledge, and then they can use the framework to develop services. The framework does not require developers to change their coding habits, but adapts itself to the needs of developers.

In terms of affinity with the same process , in the same process, the communication between different Netty instances is transmitted through memory, without network transmission, and the data transmission speed is extremely fast. Same-process affinity means that access to the game logic server in the same process is given priority. When there is no game logic server in the same process that can handle the request, it will go to other processes or machines to find the game logic server that can handle the request; To put it simply, the framework is very intelligent in processing requests, and will give priority to the logic server in the same process for consumption.

In terms of development experience, ioGame pays great attention to the developer's development experience; the framework provides many rich functions such as JSR380 verification, assertion + exception mechanism, business code positioning , etc., making the developer's business code more clear and concise;

In terms of business concurrency, the framework solves the concurrency problem of a single player for developers, and also provides a solution to the concurrency problem of multiple players in the same room or business; the framework provides friendly support for thread scalability, and Not only can provide rigid thread number settings; please refer to  ioGame thread related for details .

In terms of distributed development experience, it is usually necessary to start multiple processes when developing distributed applications. This will make debugging and troubleshooting very difficult, thereby reducing developer efficiency and increasing workload. This is a problem that many frameworks cannot solve , but ioGame has done it! ioGame supports multi-server single-process startup, which makes it easier for developers to develop and debug step-by-step systems.

In terms of docking and joint debugging with the front end, ioGame provides an auxiliary function for generating game files , so that the code is the docking file . Simply put, when the business code is written, the framework will automatically generate the latest documents. If there is no generation of game documents, then you will have to spare some time to write and maintain docking documents, and when the number of teams increases, the documents will be messy, out of sync, not up to date, and forget to update, etc. .

In terms of deployment, ioGame supports multi-server, single-process deployment, and multi-server, multi-process, and multi-machine deployment; the deployment method can be switched at will without changing the code. In daily life, we can develop according to single thinking, and when it comes to production, we can choose to use multi-process deployment.

In terms of simulated client testing, ioGame provides a pressure test & simulated client request module. This module is used to simulate the client and simplify the simulation workload, only need to write the corresponding request and callback. In addition to simulating simple requests, it can usually do some complex request orchestration and support the pressure testing of complex services. The process of mock testing is interactive, but also supports test automation. Different from the unit test, this module can simulate the real network environment, and the interaction with the server during the simulation test is sustainable and interactive .

In terms of architectural flexibility , the architecture of ioGame consists of three parts: 1. Game external server, 2. Broker (game gateway), 3. Game logic server; the three can be independent of each other or integrated with each other. Therefore, using ioGame can meet almost any deployment method, and can adapt to different types of games according to your needs, and it is simple to do these tasks in ioGame.

The project modules written by developers based on ioGame are usually well-organized, thanks to the reasonable design of the framework for routing , and also provide elegant access control for routing . When we organize these modules, it will be a good help for other developers to take over the project or follow-up maintenance ( module arrangement and suggestions ). Maybe you can't feel the power of this piece at this stage, but as you use it in depth, you will realize the many benefits and advantages of this design.

Projects written by developers based on ioGame usually have concise syntax, high performance, and low latency; the framework requires at least JDK17, so that the project can enjoy the improvements brought by ZGC and the simplicity of syntax. Starting from JDK17, ZGC is far below its goal of sub-millisecond pause time, which can clean up excess memory without affecting the speed of the game. In this way, there will be no problems of lagging or crashing, which is equivalent to introducing a JVM tuning master in disguise in the project. For details, please refer to  JDK 17 garbage collection GC performance leaps and bounds .

To sum up, ioGame is a very suitable framework for online game development. It allows you to easily create high-performance, low-latency, and easily scalable game servers, saving time and resources. If you want to quickly develop amazing online games, please don't hesitate to choose ioGame now! The framework shields a lot of complex and repetitive work, and can clearly organize and define the functional module structure and development process in the project , reducing subsequent project maintenance costs.

The framework provides good support at all stages of development, deployment, stress testing & simulation testing.. etc. I believe you have already had a preliminary understanding of ioGame. Although there are still many rich functions and features that have not been introduced, you can gain a deeper understanding through the follow-up practice. Thank you for reading, and look forward to your use of ioGame to build your own game server.


ioGame consists  of [ Network Communication Framework ] and [ Business Framework ].

  • Network communication framework : the responsibility is network communication between servers
  • Business framework : Responsibility is how business logic is handled and written

Network Communication Framework 

SOFABolt  is a set of network communication framework based on Netty developed by Ant Financial Services Group.

  • In order to allow Java programmers to focus more on the implementation of business logic based on network communication , rather than too much entanglement in the implementation of the underlying NIO of the network and dealing with network problems that are difficult to debug, Netty came into being.
  • In order to allow middleware developers to focus more on the realization of product functions and features, instead of repeatedly manufacturing the wheels of the communication framework, SOFABolt came into being.

Bolt's name is taken from the Disney animation - Lightning Dog. It is a lightweight, easy-to-use, high-performance, and easy-to-extend communication framework based on Netty best practices .

business framework

If  the sofa-bolt  is to allow Java programmers to focus more on the implementation of business logic based on network communication . The business framework is to solve the problem of how to implement the business logic conveniently . The business framework is a part of the game framework. Its responsibility is to simplify the business logic implementation of programmers. The business framework enables programmers to quickly start writing game business.

The business framework combines  asm  with design patterns such as Singleton, Flyweight, and Command for each action (that is, the processing method of the business), and obtains the action through array, which is a near-native way.

In a single thread, the business framework can execute 11.52 million times of business logic per second on average


Architecture diagram

Through ioGame, you can easily build a cluster-less central node, cluster automation, and step-by-step online game server

Lock-free asynchronous and event-driven architecture design, cluster without central node, built-in load balancing, distributed support, dynamic increase or decrease of machines, design to avoid class explosion;

Each game external server, each game logic server, and each broker (game gateway) in the figure can be deployed in a separate process, and logic servers can communicate across processes (the game external server is also a type of logic server) .

Game Gateway Cluster

The broker (game gateway) supports cluster deployment. The use of the cluster is simple. The cluster has no central node, cluster automation, and its own load balancing . ioGame itself includes service registration, and you don't need to connect an external service registration center, such as Eureka, ZooKeeper, etc. (saving server costs in disguise).

Through the intervention of the broker (game gateway), the previous very complicated load balancing design, such as service registration, health check (available in subsequent versions), connection maintenance to the server, etc., is no longer needed in ioGame, and the structure is simple a lot. In fact, the performance of a single broker (game gateway) is already sufficient, because the game gateway only performs forwarding.

logic server

The logic server usually refers to the game external server and the game logic server. There can be many logical servers, and the theoretical upper limit of the number of logical server extensions is the connection upper limit of netty.

 

Game external server

The external server maintains a long connection with the user (player). Let's make a hypothesis first. If one of our hardware supports us to establish a user connection limit of 5,000 people, when the number of users reaches 7,000, we can add an additional external server for diversion and decompression. Due to the simplicity of the game's external server expansion, it means that the number of simultaneous online players can easily reach millions, tens of millions, or even more.

Even if we start multiple external servers of the game, developers don’t need to care about which game external server these players are connected to. These players can always receive broadcast (push) messages, because the framework has already done these things ;From the player's point of view, we only have "one" server. Similarly, from the developer's point of view, we only have "one" game external server;

In terms of structural combination (deployment diversity)

In terms of deployment, it supports multi-server and single-process deployment (similar to a single application, and debugging is more convenient in step-by-step development) , and also supports multi-server, multi-process, and multi-machine deployment.

The architecture consists of three parts: 1. Game external server, 2. Broker (game gateway), 3. Game logic server; the three can be independent of each other or integrated with each other , such as:

  • The three parts of the game server, Broker (game gateway), and game logic server are in one process; [ Single application ; debugging is more convenient when developing step-by-step ]
  • The three parts of the game server, Broker (game gateway), and game logic server are in multiple processes; [ distributed ]
  • The two parts of the game server and Broker (game gateway) are in one process; while the game logic server is in multiple processes; [similar to the traditional architecture of previous games ]
  • It is even possible to not need the external server of the game, but only use the two parts of Broker (game gateway) and game logic server for other system services ;

Because ioGame follows the object-oriented design principles (Single Responsibility Principle, Opening and Closing Principle, Literary Replacement Principle, Dependency Inversion Principle, Interface Segregation Principle, Dimiter’s Law), etc., the responsibilities of the architecture are clearly defined and can be combined flexibly;

The game external server is one of the three parts of the architecture, and the default game external server is implemented based on netty. If necessary, in the future we can also use communication frameworks such as  mina and smart-socket  to provide an additional implementation of the game's external server; even if we use the  game's external server provided by mina and smart-socket  , it will not affect the existing The game logic serves the business logic, because the game satisfies the single responsibility principle for the external server, and only maintains user (player) long-term connections.

Almost all developers have encountered such a situation; in the initial stage of the project, it is usually developed in the form of a single project, and as the demand continues to increase and iterate, it will evolve into a bloated project; Carrying out splits is difficult and costly. even uncompletable, resulting in a complete refactoring;

ioGame provides a variety of deployments in terms of structural combination. Through combination, these split problems can be avoided at the early stage of the project. In the development phase, we can use the monolithic application development thinking, which reduces the development cost. Through the development method of single application, debugging is more convenient when developing step-by-step projects; this can not only take into account step-by-step development, split project modules, but also reduce the development cost of the team;

Architecture advantages

The architecture has a high degree of abstraction, allowing designers to focus more on the business without having to consider issues such as the underlying implementation and communication parameters.

The location transparency of the logic server; at the same time, due to modularization and abstraction, the coupling between the servers of the entire architecture is very low, and the logic server can be used immediately after registration, which greatly increases scalability and maintainability, and makes dynamic expansion easy And efficient. Since the logic server is registered to the Broker (game gateway), the logic server can be dynamically added, deleted, and changed; since the coupling between the logic servers is small, the debugging and testing work is also controllable;

The clearer structure is that the game external server is responsible for maintaining client access (connection of users and players), the game logic server is responsible for the business logic, and the broker (game gateway) is responsible for the scheduling between them; because of the split architecture Reasonable, so it is particularly convenient to use k8s to freely deploy these three servers. Whichever server has a high water level can be expanded, and the water level can be reduced when the water level passes.


Game programming can be made easy through ioGame, the following is a business example

Protocol file definition

First, we customize a protocol file, which is used as our business carrier description. This protocol is written in pure java code, using jprotobuf, jprotobuf is a  simplified use of google protobuf , with the same performance. 

This can be understood as DTO, POJO, business data carrier, etc., the main purpose of which is for the transmission of business data;

/** 请求 */
@ProtobufClass
@FieldDefaults(level = AccessLevel.PUBLIC)
public class HelloReq {
    String name;
}

Action

The programming of the game server , after the game server receives the business data, it processes the business data. This business code can support TCP, WebSocket, UDP at the same time.

@ActionController(1)
public class DemoAction {
    @ActionMethod(0)
    public HelloReq here(HelloReq helloReq) {
        HelloReq newHelloReq = new HelloReq();
        newHelloReq.name = helloReq.name + ", I'm here ";
        return newHelloReq;
    }
}

 A method represents an Action (a business action) in the business framework .

The parameter of the method name is used to receive the business data passed in by the front end. When the method returns, the data can be received by the front end of the game. Programmers don't need to care about the internal details of the business framework.

As can be seen from the above example, this is no different from ordinary java classes, and this design method avoids class explosion . If you are only responsible for writing game business , then the learning of business framework can stop here.

Game programming is that easy !

 

Q: Can I start programming the game server?

Yes, you can already start programming the game server.

 

Access example (console)

When we access  the here  method (usually requested by the game front end), the console will print

┏━━━━━ Debug. [(DemoAction.java: 4 ).here] ━━━ [cmd: 1 - subCmd: 0 - cmdMerge: 65536 ] 
┣ userId : 888 
┣ Parameters: helloReq : HelloRe q(name=Tower Tom) 
┣ Response: HelloRe q(name=Tam, I'm here ) 
┣ Time: 0 ms (total time spent on business methods) 
┗━━━━━ Debug [DemoAction.java] ━━━ [Current thread: RequestMessage -8-1 ] _ _ _

 

Console printing instructions

Debug. [(DemoAction.java:4).here]:
    表示执行业务的是 DemoAction 类下的 here 方法,4 表示业务方法所在的代码行数。
    在工具中点击控制台的 DemoAction.java:4 这条信息,就可以跳转到对应的代码中(快速导航到对应的代码),这是一个开发良好体验的开始!
userId :  
    当前发起请求的 用户 id。
参数 :  
    通常是游戏前端传入的值。
响应:
    通常是业务方法返回的值 ,业务框架会把这个返回值推送到游戏前端。
时间:
    执行业务方法总耗时,我们可根据业务方法总耗时的时长来优化业务。
路由信息:[cmd - subCmd]
    路由是唯一的访问地址。

With the above information, game developers can quickly locate the problem. If there is no visual information, a lot of time will be wasted in communication between the front and back ends during development. Questions include:

  • Whether to pass parameters (the front end of the game said)
  • Whether to respond to the question (the game backend says it returned)
  • Business execution time problem (the front end of the game says it has not received a response, but the back end of the game says it has responded long ago)

Among them, the code navigation allows developers to quickly jump to the corresponding code of the business class. In a multi-person cooperation project, we can quickly know which methods have been executed by the business, so that we can quickly read or modify it;

built-in function

A variety of optional modules are built in, which can be selected on demand to facilitate application development:

  • Domain events  ( lightweight stand-alone fastest MQ --  disruptor ; through the domain event module, you can implement similar Guava-EventBus, Spring event-driven model ApplicationEvent, business decoupling, avoid concurrency, and not block the main thread for your system... etc., various wave operations)
  • Task delayer  (the task can be executed, suspended, canceled, etc. at a certain time in the future, not a task scheduling similar to Quartz)
  • Multi-environment switching  (configuration support in different operating environments)
  • light-jprotobuf  ( to make up for jprotobuf's requirement that multiple objects cannot be generated in a single .proto source file, and to simplify jprotobuf's comments on source files )
  • Step-by-step lock  (simple implementation based on Redisson)

Other features built in:

For the crowd?

  1. I have been engaged in web internal system developers for a long time, and I want to know about the game
  2. new to game development
  3. Those who have never engaged in game development, but are interested in it
  4. Learners who are interested in the application of design patterns in practice and sofa-bolt
  5. receptive to new things
  6. Those who want to give up their ancestral codes

Recommend people with more than one year of practical programming experience

ioGame  provides a wealth of online high-quality documentation to help your team, bring your friends along, so you don't have to teach them hand in hand.

Guess you like

Origin www.oschina.net/news/254262/iogame-17-1-54-released