|
CSCI A348/548
|
players
directory hierarchy, compressed and archived it. Included below you will see all
the steps, with a few comments here and there. First we start by creating the hierarchy.
burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman burrowww.cs.indiana.edu% ls -ld players ls: players: No such file or directory burrowww.cs.indiana.edu% mkdir players burrowww.cs.indiana.edu% cd players burrowww.cs.indiana.edu% mkdir NBA burrowww.cs.indiana.edu% mkdir ATP burrowww.cs.indiana.edu% mkdir programs burrowww.cs.indiana.edu% mkdir NBA/Pacers burrowww.cs.indiana.edu% cd NBA burrowww.cs.indiana.edu% mkdir Lakers burrowww.cs.indiana.edu% cd Lakers burrowww.cs.indiana.edu% emacs Kobe burrowww.cs.indiana.edu% cat Kobe This is the file about Kobe. burrowww.cs.indiana.edu% cd ../Pacers burrowww.cs.indiana.edu% emacs Reggie burrowww.cs.indiana.edu% cat Reggie This is the file about Reggie. burrowww.cs.indiana.edu% emacs Austin burrowww.cs.indiana.edu% cat Austin This is the file about Austin. burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/players/NBA/Pacers burrowww.cs.indiana.edu% cd ../../ATP burrowww.cs.indiana.edu% emacs Pete burrowww.cs.indiana.edu% cat Pete This is the file about Pete. burrowww.cs.indiana.edu% cd ../programs burrowww.cs.indiana.edu% emacs one burrowww.cs.indiana.edu% burrowww.cs.indiana.edu% ls-l ls-l: Command not found burrowww.cs.indiana.edu% ls -l one -rw-r--r-- 1 dgerman students 33 Sep 11 14:26 one burrowww.cs.indiana.edu% chmod +x one burrowww.cs.indiana.edu% ./one Hi! burrowww.cs.indiana.edu% cat one #!/usr/bin/perl print "Hi!\n"; burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/players/programs burrowww.cs.indiana.edu% cd ../.. burrowww.cs.indiana.edu% du -a players 1 players/NBA/Pacers/Reggie 1 players/NBA/Pacers/Austin 3 players/NBA/Pacers 1 players/NBA/Lakers/Kobe 2 players/NBA/Lakers 6 players/NBA 1 players/ATP/Pete 2 players/ATP 1 players/programs/one 2 players/programs 11 players burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman burrowww.cs.indiana.edu% ls -ld players* drwxr-xr-x 5 dgerman students 512 Sep 11 14:23 players
And once we have it, we create an archive out of it.
burrowww.cs.indiana.edu% tar cvf players.tar players players/ players/NBA/ players/NBA/Pacers/ players/NBA/Pacers/Reggie players/NBA/Pacers/Austin players/NBA/Lakers/ players/NBA/Lakers/Kobe players/ATP/ players/ATP/Pete players/programs/ players/programs/one burrowww.cs.indiana.edu% ls -ld players* drwxr-xr-x 5 dgerman students 512 Sep 11 14:23 players -rw-r--r-- 1 dgerman students 10240 Sep 11 14:29 players.tar
Now that we have the archive we can delete the original hierarchy of files.
Once we're left with nothing but the archive, we compress it.burrowww.cs.indiana.edu% rm -ir players rm: descend into directory `players'? y rm: descend into directory `players/NBA'? y rm: descend into directory `players/NBA/Pacers'? y rm: remove `players/NBA/Pacers/Reggie'? y rm: remove `players/NBA/Pacers/Austin'? y rm: remove directory `players/NBA/Pacers'? y rm: descend into directory `players/NBA/Lakers'? y rm: remove `players/NBA/Lakers/Kobe'? y rm: remove directory `players/NBA/Lakers'? y rm: remove directory `players/NBA'? y rm: descend into directory `players/ATP'? y rm: remove `players/ATP/Pete'? y rm: remove directory `players/ATP'? y rm: descend into directory `players/programs'? y rm: remove `players/programs/one'? y rm: remove directory `players/programs'? y rm: remove directory `players'? y burrowww.cs.indiana.edu% ls -ld players* -rw-r--r-- 1 dgerman students 10240 Sep 11 14:29 players.tar
burrowww.cs.indiana.edu% gzip players.tar burrowww.cs.indiana.edu% ls -ld players* -rw-r--r-- 1 dgerman students 448 Sep 11 14:29 players.tar.gz
Notice the new extension, and the new size (about 20 times smaller).
From here on we go backwards, recovering the original hierarchy.
burrowww.cs.indiana.edu% gunzip players.tar.gz
Uncompress the file.
burrowww.cs.indiana.edu% ls -ld players* -rw-r--r-- 1 dgerman students 10240 Sep 11 14:29 players.tar
Then unpack the archive.
burrowww.cs.indiana.edu% tar xvf players.tar players/ players/NBA/ players/NBA/Pacers/ players/NBA/Pacers/Reggie players/NBA/Pacers/Austin players/NBA/Lakers/ players/NBA/Lakers/Kobe players/ATP/ players/ATP/Pete players/programs/ players/programs/one
Quick check that these are the files we had created originally.
We mentioned that this was essentially the process by which we install the Apache web server.burrowww.cs.indiana.edu% cat players/NBA/Pacers/Reggie This is the file about Reggie. burrowww.cs.indiana.edu% players/programs/one Hi! burrowww.cs.indiana.edu%
Next we finished the Perl tutorial from last time, focusing on the command line arguments.
And then we wrote a simple echo program.
burrowww.cs.indiana.edu% cat echo
#!/usr/bin/perl
while ($x = <STDIN>) {
print "Echo: ", $x;
}
burrowww.cs.indiana.edu% ./echo
Hello.
Echo: Hello.
What's up.
Echo: What's up.
You repeat everything don't you.
Echo: You repeat everything don't you.
I said it first
Echo: I said it first
Bye
Echo: Bye
^Cburrowww.cs.indiana.edu%
Next we discussed how we could write the following simple perl server.
#!/usr/bin/perl
use IO::Socket;
$sock = new IO::Socket::INET ( LocalHost => 'www.burrow.cs.indiana.edu',
LocalPort => 10000,
Proto => 'tcp',
Listen => 5,
Reuse => 1
);
die "Socket could not be create. Reason: $!" unless $sock;
while ($new_sock = $sock->accept()) {
while (defined ($buf = <$new_sock>)) {
print $new_sock "Echo: ", $buf;
}
}
close($sock);
In the process we introduced a few networking concepts, reproduced below. The networking world assigns each computer an internet address, also called an IP address (short for Internet Protocol), a sequence of four numbers typically written in a dot sequence. Just as you have phone aliases, computers are often given unique aliases, called DNS names. The IP number of the machine you're working can be found easily but it's easier to remember the name.
The program above uses Graham Barr's IO library (part of the standard Perl distribution) to illustrate a few points on networking. The description that follows (and the program above) are both taken from Sriram Srinivasan's "Advanced Perl Programming" that I brought with me in class. Here we go:burrowww.cs.indiana.edu% nslookup www.burrow.cs.indiana.edu Server: moose.cs.indiana.edu Address: 129.79.254.191 Name: burrowww.cs.indiana.edu Address: 129.79.245.98 Aliases: www.burrow.cs.indiana.edu burrowww.cs.indiana.edu%
Just as you would ask the phone company for a telephone number and a physical handset, both sended and receiver ask the module to create sockets. Sockets, like telephones, are bidirectional endpoints: once a connection is established, either side can send and receive data, as long as there is an understanding between the two programs about the direction of communication.
Because only the receiving side needs to have a well-known address, we create the receiving socket as follows (this is an excerpt from the program above):
use IO::Socket;
$sock = new IO::Socket::INET ( LocalHost => 'www.burrow.cs.indiana.edu',
LocalPort => 10000,
Proto => 'tcp',
Listen => 5,
Reuse => 1
);
die "Socket could not be create. Reason: $!" unless $sock;
The IO::Socket::INET module provides a nice wrapper for Internet domain sockets. The
LocalHost and LocalPort parameters specify the host and port on which this
socket is going to listen.
So overall it looks as if we import java.util; when we need a HashTable.
We then create the desired object using the new operator, and we specify the parameters to the
constructor:
LocalHost parameter needs to be the name of the machine you'd be running this server
LocalPort is a port that's not used for anything else while this server is running. That's why
I use 10000 and need to specify that the demo server (that normally runs on the port 10000)
needs to be stopped before we start this new server. 10000 used in the code must not conflict with the
port number used by any other application on this machine (otherwise, you get an error saying, "address already in use").
Reuse option, because if this program ends without properly closing the socket and is
subsequently restarted, it will complain about the socket being in use.
Listen option specifies
the maximum number of callers that can be put on hold while they are dialing this number, figuratively
speaking.
Once created, the socket is all set to receive incoming calls. The accept() method listens on the
given port until another program attempts to connect to it. At this point, accept returns a new socket:
$new_sock = $sock->accept();
This is analoguous to a switchboard operator indicating a different handset for you to converse on, while he goes back to
waiting for the main number to ring. Messages sent by the client can now be obtained by reading from $new_sock.
You can use this socket as a filehandle and call any of the input operators, such as <>. It will return
undef on an end of file condition.
Once you receive something you write it back to the socket.
Here's how you start the server:
burowww.cs.indiana.edu% ./server
And here's how you access it from some other machine, e.g. tucotuco.cs.indiana.edu:
tucotuco.cs.indiana.edu% telnet www.burrow.cs.indiana.edu 10000 Trying 129.79.245.98... Connected to burrowww.cs.indiana.edu. Escape character is '^]'. I am here Echo: I am here You don't say... Echo: You don't say... OK, I need to go now Echo: OK, I need to go now Bye. Echo: Bye. ^C^? ^D Connection closed by foreign host.tucotuco.cs.indiana.edu%
A348/A548.