Introduction Manual Class Reference Header Reference

Entering Zoidmode

Entering Zoidmode

After a connection has been spawned, it is possible to transmit data using ZCom_Control::ZCom_sendData() and do some other basic things. For Zoidcom to actually start replicating nodes to clients, the connections need to enter a Zoidlevel. This is achieved by calling ZCom_Control::ZCom_requestZoidMode() on each client. In the parameters, the target Zoidlevel is specified.

Requesting A Zoidlevel

All nodes are on Zoidlevel 1 by default. Nodes can be registered to other levels by calling ZCom_Node::applyForZoidLevel() on the server. The easiest thing to do on the client is to request Zoidlevel 1 in the connection result callback.

class Client : public ZCom_Control {
  virtual void ZCom_cbConnectResult( ZCom_ConnID _id, eZCom_ConnectResult _result, 
                                     ZCom_BitStream &_reply )
  {
    if (_result == eZCom_ConnAccepted)
    {
      printf("Connection established.\n");
      ZCom_requestZoidMode(_id, 1);
    }
    else
      printf("Connection failed\n");
  }

  // all other callback methods omitted here
};

This requests to enter Zoidlevel 1 directly after the connection has been established.

Processing A Request

On the server, another callback needs to be implemented. The purpose of this callback is to process Zoidlevel requests and grant or deny them.

class Server : public ZCom_Control 
{
  bool ZCom_cbZoidRequest( ZCom_ConnID _id, zU8 _requested_level, ZCom_BitStream &_reason )
  {
    // return true to grant the request, or false to deny it
    if (_requested_level == 1)
      return true;
    else
      return false;
  }
 
  // all other callback methods omitted here
};

This code will accept all requests to enter Zoidlevel 1. After a request has been accepted, the server will start replicating nodes from level 1 to the client.

Process The Reply

The client will see the result of the request through the callback ZCom_Control::ZCom_cbZoidResult().

class Client : public ZCom_Control 
{
  void ZCom_cbZoidResult( ZCom_ConnID _id, eZCom_ZoidResult _result, zU8 _new_level, ZCom_BitStream & _reason )
  {
    if (_result == eZCom_ZoidEnabled)
      printf("Zoidlevel %d entered\n", _new_level);
    else
      printf("Failed entering Zoidlevel %d\n", _new_level);
  }
 
  // all other callback methods omitted here
};

When entering a Zoidlevel for the first time, server and client will exchange their class registries. If the server knows a class which the client does not, the client will receive the result eZCom_ZoidFailed_System as _result parameter to the zoid result callback.


This file is part of the documentation for Zoidcom. Documentation copyright © 2004-2008 by Jörg Rüppel. Generated on Sat Aug 16 15:26:51 2008 for Zoidcom by doxygen 1.4.6-NO