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.

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".

Make sure to Log the Event.

During technical support, the most common problem is that it is difficult to find the cause of the problem because it is not logged. In particular, be sure to log the following events and functions that take errorInfo as a parameter.

  • OnError: Callbacks information about errors or usage issues that occur inside ProudNet.

  • OnWarning: Callback information that is not critical but potentially problematic.

  • OnInformation: Callback information about the internal situation, tracking, etc.

  • OnException: Callback internal Exception error information.

You can easily get information about the problem by using errorInfo -> ToString(); in the parameter errorInfo.

Last updated