Vizard 7 » Reference » Networking » Networking basics

Networking Basics

Vizard's networking features enable sending data between computers.


Some applications of networking include:

Creating a network connection

To create a network connection to another computer, use the viz.addNetwork command. The command takes the name of the remote computer or the IP address as the argument (e.g.,, or The following code will create a network object which will send data to the computer '':

myNetwork = viz.addNetwork('')

Sending data

To send data over a network connection to a Vizard/Python application use the <network>.send() command. The send command takes any number of position or keyword arguments. Vizard serializes the arguments to a string and sends that to the remote computer. To serialize the data, Vizard uses the cPickle library that comes with Python. Any object that can be used with the cPickle library can be sent over the network. This means almost any type of data can be sent to the other computer.


Here is an example that sends both positional and keyword data over the network connection:


To send data to a non-Python application use the <network>.sendRaw command. This command takes a single string value that is sent as raw byte data to the network object:

myNetwork.sendRaw('Some raw data')

By default, Vizard sends/receives network data over UDP port 4950. You can change the port of a network object using the <network>.port() command. For example, to send data over port 4960, you would use the following code:


Receiving data

When a network message is received Vizard will trigger the viz.NETWORK_EVENT. In order to handle the data you simply need to register a callback for this event. Depending on how the data was sent, the callback function will be passed either a viz.NetworkEvent or viz.RawNetworkEvent object.


A viz.NetworkEvent object will be passed to the callback function if the data was:

The following code receives data sent from the previous myNetwork.send example:

def onNetwork(e):
    print('** Received message from',e.sender)
    print(    )#Prints: (5, 'hello', [1, 2, 3])
    print(     )#Prints: 78
    print(     )#Prints: ['more', 'data']

The viz.NetworkEvent object contains an attribute called data, which is a tuple containing all of the position arguments in the order they were passed. All the keyword arguments are transformed into direct attributes of the network object. In our send example, the keyword arguments foo and bar were used to send data. In our receiving example, we were able to directly access these values as attributes of the network event object.


A viz.RawNetworkEvent object will be passed to the callback function when a raw byte network packet is received. This is useful for receiving data from non-Python based applications. The raw_data attribute of the event structure is a Python bytes object that contains the data:

def onNetwork(e):
    if isinstance(e,viz.RawNetworkEvent):


In addition to data attributes both network event objects include information about the sending computer and the receiving port:




sender: The name of the computer that sent the message.

address: The IP address of the computer that sent the message.

port: The port number the message was received on.


address: The IP address of the computer that sent the message.

port: The port number the message was received on.

As mentioned previously, Vizard sends/receives network data over UDP port 4950 by default. You can tell Vizard to receive data on other ports as well. For example, if you want to also receive data over port 4960 you can use the following code:

If you ONLY want to receive data on port 4960, then you can tell Vizard to stop receiving data on the default port of 4950 by using the following code:

See also

In this section:


Multi User Environment

Networking Command Table

Cluster basics

Other sections:

Tutorial: Network communication

Example scripts:

Robo chase

Instant messenger