Networking provides a way for data exchange between several devices. It is a principal component that allows remote control of some parameters inside applications of mobile and tablet devices, and is also used to make interactive projects working in a synchronized manner on several computers. In this chapter, you will learn how to implement and use OSC and TCP protocols in your openFrameworks projects as follows:
Networking comprises a number of hardware and software technologies that provide data exchange among digital devices and even among applications inside a computer. The most popular network model today is called TCP/IP (Transmission Control Protocol/Internet Protocol). It works using wired (LAN—Local Area Network) or wireless (WLAN—Wireless LAN) connections. All the modern computers and mobile devices have support of TCP/IP.
Another networking technology is wireless ZigBee networks, widely used in physical computing projects. Connecting just two devices can be considered as the simplest network. Old but still popular technologies for wired connections are USB, serial port (RS-232), RS-485, and I2C (used for micro devices).
In this chapter, we will consider usage of TCP/IP for connecting several devices inside a local network. Local network is built and controlled by network router. A network router is a special network node working as a separate device or integrated within your laptop.
The network router gives a unique identifier, called network address, to each device connected to the network. The address has a form such as 192.168.0.3
, or can be a computer name, such as My machine
. Each device can refer to itself using the address, localhost
, or its equivalent, 127.0.0.1
. See the properties of your network adapter to find out the network address of your device. You can also request the network information using the Terminal window, by entering the ipconfig
command (for Windows) or the ifconfig
command (for Mac OS X and Linux).
For testing the connection between two computers with known addresses, use the ping
command, for example, ping 192.168.0.3
. If the connection is not established, it is probably blocked by your router's or computer's firewall or antivirus. In this case, check their settings.
For sending some data from one device to another, you should specify the network address of the destination device, and also the port number, which is an integer number between 0 and 65535. Some ports are reserved, for example, port 80
is used for HTTP protocol exchange by your browser. In the chapter examples we will use port 12345
.
Ports with high numbers (greater than 10,000) are rarely used by system services, so most probably you can use them. To find out which ports are used in your system, use special software or networking commands from Terminal. For connecting devices, we often use ports 12345
, 12346
, 12347
, and 12348
.
In this chapter we will learn how to use the following two protocols for data transmission:
Let's start with OSC protocol.