Event handling

Working with event handlers

ProudNet's event handling is in the delegate pattern.

The client implements it by inheriting from class Proud.INetClientEvent, and the server implements it by inheriting from class Proud.INetServerEvent. After creating instances of the classes you implemented, you need to associate them with Proud.CNetServer.SetEventSink on the server and Proud.CNetClient.SetEventSink on the client.

class MyEvent:public INetClientEvent
{
    virtual void OnJoinServerComplete(...) override 
    { 
        // my event handler
        ...
    }
}
 
MyEvent m_myEvent;
myNetServer->SetEventSink(&m_myEvent); 

If you are using a compiler that supports C++11, you can do more concise programming by using lambda expressions instead of inheriting the class above.

myNetServer->OnJoinServerComplete = [...](...) 
    {
        // my event handler
        ...
    };

See About main loop or more information on when you can receive event callbacks from the above process.

Linking event handlers on the client

Typical events that can occur on the server include "receiving a connection from a client" and typical events that occur on the client include "establishing a connection with the server" and "joining a P2P member".

Last updated