22.Sending a message

Let's assume RMI Foo(int a,float b) is declared.

If RMI proxy is registered to either Proud.CNetClient or Proud.CNetServer, RMI of Proxy can be called to send a message.

Messaging protocol can use either Proud.RmiContext.ReliableSend or Proud.RmiContext.UnreliableSend which can be used for client-server communication as well as P2P communication. More information about messaging protocol is guided in 3. Protocol type of ProudNet.

Here is an example how a message is sent.

Proud::HostID oneHostID=...; // A target to send
int manyHostIDListCount=...;

// Send RMI to server
myProxy.Foo(Proud::HostID_Server,Proud::RmiContext::ReliableSend,3,4);

// Send RMI to the target
myProxy.Foo(oneHostID,Proud::RmiContext::UeliableSend,3,4);

The target to send a message can be Host ID of client / server (Proud.HostID_Server) or yourself. If you set the target to send as P2P group by inserting its group ID then it performs Multicast.

You can Multicast a message to several targets at one time. All you need to do is to insert HostID distribution pointer and the size of HostID distribution as the first parameter instead of HostID. (Example below)

// Target distribution
Proud::HostID sendTo[2];
sendTo[0] = ...;
sendTo[1] = ...;

// Send a message to several targets
myProxy.Foo(sendTo, 2, Proud::RmiContext::ReliableSend, 3, 4);

If targets overlap from the list then it doesn't send the message repetitively to the same target. In the list, you can either appoint one host or P2P group as a target.

ProudNet offers several message-send options. For more details, please refer to Proud.RmiContext.