ProudNet.Eng
WebsiteProud ConsoleLanguage
  • 🌐ProudNet
    • ProudNet Introduction
    • Download and Install
      • How to verify your ProudNet license
      • AMI
    • Project Settings
      • C++
      • C#
      • Mac Xcode
      • Linux
      • Unity3D
        • iOS Build
      • Unreal Engine 4
      • Running the PIDL Compiler
    • Using ProudNet
      • Server and Client
        • Utilization of Server
        • Utilization of Client
      • RMI
        • Utilization of RMI
      • PIDL
        • Utilization of PIDL
      • Event handling
      • Communication messages
      • P2P Communication
        • Using P2P communication
    • Utilization of ProudNet
      • How to use
      • Tips for performance
    • Using DB in ProudNet
      • DB Cache System ver.2
        • DB Cache Theory and Understanding
        • Install DB Cache and Set Up Network
        • DB Cache Server and Client
        • DB Cache usage and application
          • Utilization of DB Cache
      • ADO API
      • ODBC API
    • ProudNet Utility
  • ProudNet Note
    • Technical Notes
      • Main Loop
      • Setting up a server firewall
      • Encryption and decryption
      • What to do in case of an error
      • List of error messages
      • Synchronizing Character Position
      • Client-Server Communication
      • MiniDump (Error Dump System)
      • [Version 1.6] Server-to-Server LAN Communicator
    • Glossary
    • Sample examples
  • 🌐Proud Service
    • Guide for Console
    • ProudChat
      • Download SDK
        • C++
        • C#
        • Unity3D
        • Unreal Engine 4
      • Features in Console
Powered by GitBook
On this page
  • Client Main Loop
  • Server Main Loop
  • - Receive and event callbacks
  • - Timer callback
  1. ProudNet Note
  2. Technical Notes

Main Loop

PreviousTechnical NotesNextSetting up a server firewall

Last updated 1 year ago

Client Main Loop

ProudNet's clients are polled, meaning that when a message is received or an event occurs, RMI call callbacks or event handler callbacks are only called on the thread that called the specific function in the game client main loop.

Unintended threaded behavior occurs mainly because game clients have fast-turning loops, and designing in the above way frees client developers from the burden of complex threaded programming.

Server Main Loop

- Receive and event callbacks

The game server utilizes all CPUs and utilizes Thread pooling to process reception for other clients while accessing the DB. ProudNet also operates in this manner and has the following features.

  • The game client must call a function for incoming processing at regular intervals to handle the accumulated incoming messages, but the server does not need to make these calls.

  • When an event or RMI reception occurs on the server, it will be callbacked from the thread pool that the Server has.

  • Events or RMIs for the same client will not be called from more than one thread at the same time, but ProudNet will always call RMIs in order of arrival. Of course, events and RMIs for different clients will be callbacked simultaneously.

  • If an RMI or event occurs while all threads are executing the callback routine, the callback will not occur immediately, but the callback will be queued until a thread completes the callback routine.

  • Longer execution times for user-implemented callback routines will not break network communication, so there is no need to implement a separate thread pool for them.

The following image shows the status of clients A, B, and C as they are accommodated on the server and waiting in a queue on the server due to an RMI or event, respectively.

A1,A2,A3 -> Events or RMI for Client A B1,B2,B3 -> Events or RMI for Client B There are a total of 2 threads in the thread pool.

At that point, the rule will execute as follows.

  • A1,A2,A3 will not run at the same time.

  • B1,B2,B3 and C1,C2,C3 are also not executed at the same time.

  • One of A1,A2,A3 and one of B1,B2,B3 and one of C1,C2,C3 can be executed at the same time.

  • Since there are only two threads in the thread pool, two of A, B, and C are selected and called back, but the thread whose callback routine is completed first performs the RMI or event callback for the client that was not selected.

- Timer callback

Like game clients, game servers may also want to process something at certain intervals. In this case, you can have a simple loop like the one below.

while(1)
{
    do_something(); // Perform World Transition Operations
    Sleep(1); // Wait for a period of time
}

You can also use Proud.CTimerThread or Proud.CTimerQueue to run the above loop in a separate thread. However, we prefer to have the user-defined timer function called directly from the server thread pool.

For example, if the server has only one thread, the number of critical section accesses can be saved if the timer function and event callback are on the same thread. Please note that ProudNet also has these features built-in.

When the server starts, it creates a separate .

Thread pool
Client Main Loop
Example of running a thread pool