This tutorial will teach you how to network Vizard worlds so that more than one user can inhabit the same environment. Networking also allows you to create systems in which a monitor can watch and manipulate a world remotely. Either way, two or more users located anywhere in the world can participate in the same virtual experience.
This content is discussed in more detail in the reference section.
For this demonstration we will make a simple world in which two users are represented by two robots in the middle of a maze. The movement and orientation data of each user will be sent to the other user to animate a robot in the other's world. To create this scenario, we will write a script that can run independently on the two separate computers. First let's set up the world:
If you have trouble getting the code in this tutorial to work, you can find the complete example script networking.py in the \tutorials\networking directory.
Now add the code that allows the computers to communicate. Think of this communication as a mail system. First, you'll set up a mailbox to send mail. All Vizard needs to know is the name of the recipient computer.
Now add the information that you are going to put into that mailbox. We will use a timer to send messages so that the recipient has our current location and orientation.
That's all it takes to send the information.
Now, add the code to receive and process the data using a Vizard event function designed for networking. This event will be running all the time in the background of your world, receiving any messages from other computers:
In the code above, onNetwork(e) is called when event data is received. If the machine that sent the data matches the target machine the following line of code gets executed:
Here e.action is updatePlayer, the value specified in the action attribute of the send command. The event data is then passed to updatePlayer where Steve's transform matrix gets updated.
If you have another computer running Vizard on your network, you are now ready to link the two worlds. Just find out the networks name for both computers and give it a go.