Connection between 2 computers to exchange messages.

Consists of


Some uses of networking, in relation to computer graphics, are:

Networking Multiple Hosts

Communication between more than 2 hosts normally involves many pair-wise connections.

Peer-to-peer model

Networking Multiple Hosts

Server-based model

Server can be a simple reflector, a database, or a whole simulation in itself


An Internet Protocol (IP) network connection uses sockets.

A socket connection involves:

Programming libraries can look up the IP address from a host name (e.g.

The port number and protocol are normally decided on in advance for a particular application.

(It is also possible to use dynamically generated port numbers.)

Network Data

A network connection allows one computer to send bytes of data to, or receive bytes of data from, another computer.

Everything beyond the exchange of raw data is higher-level interpretation of the data, handled by the application or a library.

Note that different computers can interpret a stream of bytes differently, depending on things such as "native byte ordering".

Functions to convert to & from "network byte order" help avoid problems.

Sending everything as text strings is an easy alternative.


The two major protocols are TCP/IP and UDP/IP



For applications like real-time graphics, UDP is often preferred for its speed and simplicity. But a mix of TCP and UDP can also be useful.

Python Sockets

Sockets are implemented in the socket module.

Main functions for UDP:

s = socket(AF_INET, SOCK_DGRAM) Create a UDP socket
s.bind(('',portnum)) Listen to a specific port
s.sendto(data, (host, portnum)) Send data to remote host
data, addr = s.recvfrom(maxPacketSize) Receive data; return value is tuple of data and sender
s.setblocking(0) Make the socket non-blocking. Trying to receive when no data is available will generate an exception.


Web-based Networking

Web tools such as PHP, Shockwave, and Python CGI scripts can do socket-based networking.

This can be used to communicate from a web page to a graphical program.

Example: send.php

Web-based Networking

Python's urllib or urllib2 can be used to fetch web data.

e.g. textures or sounds

        webdata = urllib2.urlopen(url).read()
        return None
    webdataAsFile = StringIO.StringIO(webdata)
    tex = Texture2D(webdataAsFile)


Assignment 5

DUE: Working draft - Thursday, 7 December 2006, in class (2:00pm)
Final version - by Friday, 15 December 2006 (via e-mail, to

Create an interactive, networked, graphical environment that can involve multiple participants.
Note that this is fairly vague; some options are:

You will have to demonstrate a functional version of your project in class on Dec 7. You may continue to work on it after that, and turn in the final version be Dec 15.
E-mail the final program, and any required data files, to me at

Creative Commons License
This document is by Dave Pape, and is released under a Creative Commons BY-2.0 License.