// this won't compile as ZCom_Control is an abstract class, apply the example to // a derived class ZCom_Control *server1 = new ZCom_Control(); ZCom_Control *server2 = new ZCom_Control(); // use control ID size 1 server1->ZCom_initSockets(true, 9999, 0, 1); server2->ZCom_initSockets(true, 9999, 0, 1);
The control ID size tells Zoidcom how many different control IDs should be possible. 1, as in this example, sizes it to 1 bit, allowing two different control IDs: 0 and 1. If you need more, the size must be increased. Note that Zoidcom needs to add the control ID to every packet sent by a ZCom_Control. Thus using a size of 32 means that all packets add 4 bytes of control id data.
Each control needs it's own unique ID from a possible range of 0 up to the above applied (size^2)-1:
Now two ZCom_Controls listen on the same UDP port, but each one will only receive packets directed to their control id.
ZCom_Control *client1 = new ZCom_Control(); ZCom_Control *client2 = new ZCom_Control(); // use control ID size 1 client1->ZCom_initSockets(true, 0, 0, 1); client2->ZCom_initSockets(true, 0, 0, 1); // connect client 1 to server 1 ZCom_Address target; target.setAddress(eZCom_AddressUDP, 0, "localhost:9999"); client1->ZCom_Connect(target, NULL); // connect client 2 to server 2 target.setAddress(eZCom_AddressUDP, 1, "localhost:9999");
ZCom_initSockets() needs the same control ID size as the servers, otherwise they won't understand the incoming packets at all. The second parameter to ZCom_Connect must be the target's control id, which in this example, are 0 and 1.