|
ICM / NotesWeek9Network
Introduction to Computational Media Week 9Networking IP, or "Internet Protocol" is a broad standard that most of the world's computers use for communication. Every internet enabled computer has a unique IP address that looks something like this- "63.23.100.243". If you are curious what your IP address is, you can visit this website- http://whatismyipaddress.com/ This is what the world thinks your IP address is. You computer probably thinks that it has a different IP address than the one above- You can check that in the following ways: Find IP address on a Mac. Mac users can also find out all sorts of useful info by using the Network Utility app. Most people access the internet through a router. A router shares an IP address with a number of computers by creating its own private network- Kind of like a mini internet that exists only between the computers connected to the router. The router talks to the rest of the internet using the external IP address, and then routes the data to a local IP address. Not only does this allow many computers to share an internet connection, but it also provides security to the connected computers. More info can be found at this link: Most of internet communication uses a client- server model. The server is a computer program that is patiently waiting for other remote connections. Other computers need to easily find this server so most servers use a "Static" IP address, or an IP address that is always the same and easily accessible throughout the internet. For example, google's IP address is 209.85.165.147 But we don't type 209.85.165.147. We type www.google.com, and thank God, because it's a lot easier to remember. Scattered around the internet are DNS servers, or "Domain Name Servers". These servers hold huge databases which can convert a name like google.com into the appropriate IP address. It is difficult to keep a server behind a router unless you have complete access to the router. By default, the router will assign a different IP address every time you connect to it, and any client trying to connect to your computer will first have to make it past the router- no easy feat. It's very unlikely that you will be able to run a server on your laptop- at least one that the rest of the world will see- using NYU's wireless network. Also, Servers need to specify a network port on which to listen for a connection. Generally using a port in the 10000 or higher range is good practice as other more standard servers don't use them. Web servers, for example, listen to port 80. Email servers listen to port 25. FTP servers listen to port 21. NYU IT services are constantly monitoring the NYU network for suspicious activity, and something that is definitely suspicious is a lot of activity on an unusual port. ITP has made an unofficial agreement with NYU IT that any activity on a port in the low 9000s is probably an ITP student and okay. If you plan to build any network servers and deply them on the floor I would stick with ports between 9000 and 9100. It's possible to create a basic connection using the telnet command in a terminal window. for example, "telnet www.google.com 80" will actually connect you to google's web server. The server is waiting for a command from the HTTP protocol. If you type "GET / HTTP/1.0" you should get all the html for google's homepage! This is basically the setup for every client and server on the internet. A server sits somewhere, listening to a specific port. A client is told to go to an IP address and try to connect to a specific port. When the server and client connect, they talk to each other using a predetermined protocol. In the case of a web server and client, it's "http" or "hypertext transfer protocol". FTP servers and clients use "File Transfer Protocol". You can create your own clients and servers using Processing's Network Library Here's a simple Server: import processing.net.*;
Server myServer;
int val = 0;
void setup() {
size(200, 200);
// Starts a myServer on port 5204
myServer = new Server(this, 5204);
}
void draw() {
val = (val + 1)%255;
background(val);
myServer.write(val);
}
use telnet to connect by typing "telnet 127.0.0.1 5204" which means "connect to IP address 127.0.0.1 (which means the local machine) on port 5204. You should see ASCII characters spitting out. These characters don't make sense because we don't know how the data is used. We need to agree on the protocol. This simple client knows what to do with the data: import processing.net.*;
Client myClient;
int dataIn;
void setup() {
size(200, 200);
// Connect to the local machine at port 5204.
// This example will not run if you haven't
// previously started a server on this port
myClient = new Client(this, "127.0.0.1", 5204);
}
void draw() {
if (myClient.available() > 0) {
dataIn = myClient.read();
}
background(dataIn);
}
This simple chat client and server illustrates most of the functionality of the Network library. Download the shared Canvas Demo here! This shared "whiteboard" client and server shows how to deal with multiple client connections. Every connected client can draw on the canvas and the information is passed through the server to every other client. |