Connection between 2 computers to exchange messages.
Consists of
Communication between more than 2 hosts normally involves many pair-wise
connections.
Peer-to-peer model
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. www.buffalo.edu).
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.)
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
TCP/IP:
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.
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 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
Python's urllib or urllib2 can be used to fetch web data.
e.g. textures or sounds
try: webdata = urllib2.urlopen(url).read() except: return None webdataAsFile = StringIO.StringIO(webdata) tex = Texture2D(webdataAsFile)
Example: texURL.py
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 depape@buffalo.edu