Chapter 11. Networking

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 basics
  • Using OSC protocol
  • Using TCP protocol for streaming images

Networking basics

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.

Tip

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.

Tip

Note that the network address can vary when restarting devices and routers. So for long-term working interactive installations, you should fix the computers' addresses in their network adapter's settings, or just use computer names instead of numbered addresses.

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:

  • OSC: Open Sound Control is very simple and fast. It's appropriate for transferring small amounts of information (such as commands for changing parameters and objects' coordinates) at fast rates. It is the main protocol used in interactive installations and physical computing projects. It is supported in all the VJ-related software.

    Tip

    Initially, OSC was made as a network replacement for MIDI, which is a wired protocol for connecting musical instruments. Now OSC is used for controlling a wide range of applications and devices, often not related to music.

  • TCP: Transmission Control Protocol is capable of easily transferring a large amount of data. It is a universal protocol. In this chapter we will see an example of using it for image streaming.

Let's start with OSC protocol.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset