Second Lecture Slides

Download Report

Transcript Second Lecture Slides

The Internet
1
The Internet is an open
system
Details publicly available
A lot of software is free
Lots of publicly available expertise
available via such things as newsgroups
Dangers with privacy
2
Implications of open systems
Wide variety of implementations, for
example of TCP/IP
Cost of implementation less
High level of compatibility
Wide variety of developers selling
products
3
Examples of open systems
and code
HTTP
TCP/IP
Java
Linux
Apache
4
Network topolocies
Bus network
Ring network
Hub network
5
Bus network
Devices: computers,
printers etc
Terminator
6
Ring network
Computer
Computer
Printer
Mass
storage
device
7
Hub network
Ports
Backplane
8
The Internet has a layered
architecture
Level of functionality
Each level draws upon facilities in a
lower level
As you proceed downwards you get
nearer the computer
Achieves separation of concerns
9
Internet history (i)
ARPA started the ARPAnet network
ARPAnet originally used the NCP
protocol
1974 Cerf and Kahn developed TCP/IP
10
Internet history (ii)
Splitting of ARPAnet into MILnet and
ARPAnet
Renaming of ARPAnet as Internet
Development of Web at CERN
Development of new protocols to cope
with huge growth
11
Internet protocols(i)
Telnet, used for connections
File Transfer Prototcol (FTP), used for
file transfer
Simple Mail Transfer Protocol (SMTP),
used for electronic mail
Kerberos, used for security functions
12
Internet protocols(ii)
Network File System (NFS), used for
transparent file sharing
Trivial File Transfer Protocol (TFTP),
used for fast transmission of files
Transmission Control Protocol (TCP),
used for fast transmission of files.
13
Internet protocols(iii)
User Datagram Protocol (UDP), used for
fast transfer of data, unreliable.
HyperText Transfer Protocol (HTTP),
used for transferring Web documents
Internet Protocol (IP), basic functioning
of moving data
14
Identifying computers on the
Internet
A basic function of any network is
naming: identifying computers and
other resources using some unique
name.
Dotted quad notation identifies an IP
address
Domain naming uses symbolic names
15
IP addresses
IP addresses expressed in dotted quad
identify a computer.
Addresses can be class A, class B, class
C or class D.
They identify a network and a computer
on the entwork.
16
An example: the class A
address
1 bit
7 bits
Network address
1 bit used to
designate
class A
7 bits used to
identify
network
24 bits
Computer address
24 bits used to
identify
computer
17
Dotted quad notation
Used to identify a computer,
four 8 bit quantities reflecting
the 32 bits used in the Internet
101.23.111.128
Example
18
The loopback address
The address 127.0.01 is known as the loop-back
address.
Any data which is sent to this address from a
computer will return straight to the computer
19
Domain Name System
Dotted quad suffers from a major
problem: difficult to remember
Better for symbolic names to be used
This is the purpose of the Domain
Name System (DNS)
20
An example
Country of origin
www.gold.ac.uk
Name of the computer
Name of
organisation
Academic
organisation,
edu used in
America
21
Some domains
com, a commercial company
edu or ac, educational insitution
gov, governmental organisation
mil, military organisation
museum, museums
22
Hierarchic naming
com
edu gov …… uk fr
mit
cs
athena
athena.cs.mit.edu
The computer
athena in the cs
department at
MIT
23
import java.net.*;
public class Whoami {
public static void main(String[] args)
throws Exception {
if(args.length < 1) {
System.err.println(
“You need to supply a Machine
name");
System.exit(1);
}
InetAddress a =
InetAddress.getByName(args[0]);
System.out.println(a);
}
24
Client and servers
A network can be envisioned as a set of
clients and servers
Servers provide a service, for example a
Web server delivers Web documents
Clients call on the services provided by
a server
25
Distributed Computing in Java
"The Network is the Computer"--Scott
McNealy, CEO of Sun Microsystems
Make computing across networks as simple
and reliable as stand-alone computing
In Java, programming across networks is
based on simple IO. So we will review that.
26
What are the main distributed computing
tasks: Remember Mickey Mouse
Fetch the Water:
Fetch some information from a distant
machine machine over there and move it to
this machine here, or vice versa.
The easiest way to do this is via Sockets.
This is based on streams and is very like IO.
We will start our Java here.
27
Make a connection to a water supply:
Connect to a database, possibly residing on
one or more other machines.
Java DataBase Connectivity (JDBC), is an
abstraction away from the messy, platformspecific details of SQL.
We will start with the messy way.
28
Make your water available:Provide services
via a Web server. Three ways to do this in
Java:
Applets: download the Java Code and run it
on your own machine
Servlets: run it on the Web server
Java Server Pages (JSPs)incorporate in web
pages.
29
Control brooms from afar:
Execute methods on Java objects
that live on remote machines. This is
accomplished with Java’s
Remote Method Invocation (RMI).
30
Integrate with other pre-written spells.
Use code written in other languages,
running on other architectures.
Common Object Request Broker Architecture
(CORBA), which is supported In Java.
31
Other Java technologies
Enterprise Java Beans
Separate out functionality from connection
JINI
Add and remove objects
32
Concurrency
Remember in Mickey: there are lots of
brooms at the same pool
There are essentially two ways to do this:
HeavyWeight Processes: keep them quiet
separate
LightWeight Proceses: interleave them
Java supports Lightweight processes through
the use of threads
33
Layers of Distribution in Java
1. Sockets
The model here is computer to computer
connection
2. RMI (Remote Method Invocation)
The model here is object to object
connection. Relies on the same semantics,
probably same language And still need to
know where it is
34
3. CORBA (Common Object Request Broker
Architecture)
Here the language and location are
abstracted away.
4. Voyager and mobile agents
Here objects can be moved
35
Ports and sockets
A port is a logical TCP/IP idea, not to be
confused with a hardware port
Ports are used for data communications
Numbered
Some ports are dedicated to certain
applications
36
Some dedicated ports
80 is used for Web traffic
25 is used for the Simple Mail Transfer
Protocol
110 is used for the Post Office Protocol
version 3 email service
21 is used for the File Transfer Protocol
37
Sockets and server sockets
A socket is a connection into a
computer
A server socket is used to create a
socket on a server
Java contains facilities for setting up
sockets and server sockets and
connecting streams
38
Address of Computer: IP Address
Address of a connection to a computer:
Port
(e.g. 25 for telnet)
Communication Channel through a port:
Socket
39
Sockets and data input in Java
Socket ss = new Socket(“igor.gold.ac.uk”, 2048);
InputStream is = ss.getInputStream();
BufferedReader bf = new BufferedReader
(new InputStreamReader(is));
Creates a BufferedReader to the
computer igor at Goldsmiths
College via port 2048, data can now
be read from igor
40
Sockets and data output in
Java
Socket ss = new Socket(“scorpio.gold.ac.uk”, 2048);
OutputStream os = ss.getOutputStream();
PrintWriter pw = new PrintWriter(os, true):
Sets up a PrintWriter object attached to
the computer scorpio at Goldsmiths
College. The client can then write data to
this computer. Note that true in the
PrintWriter constructor flushes data
from the buffer automatically
41
The ServerSocket class
Used to generate sockets at a server.
Has a constructor which specifies the
port to be used.
Method accept blocks until a client
connection is made and then generates
a Socket object.
42
Streams
Abstraction for arbitrary data streams
e.g. System.out.println()
System is in java.lang
in out and err are static fields in System
each is a stream (actually a subclass, e.g
PrintStream)
43
There are InputStreams and
OutputStreams
These are abstract classes
Children are things like input byte
streams
44
Generating streams at a
server
ServerSocket ss = new ServerSocket(200);
//Wait for a connection
while (true)
{ System.out.println (“waiting for client”);
Socket Client = ss.accept();
InputStream is = sockS.getInputStream();
OutputStream os = sockS.getOutputStream();
// is and os can then be used for communication
// to the server
45
// Time Server
import java.net.*;
import java.io.*;
import java.util.*;
public class TimeServer {
public static void main (String
args[]) throws IOException {
int port = 1234;
ServerSocket server = new
ServerSocket(port);
while (true) {
System.out.println("Waiting for
client...");
Socket client = server.accept();
System.out.println("Client from
"+client.getInetAddress()+"
connected.");
OutputStream out =
client.getOutputStream();
Date date = new Date();
byte b[] =
date.toString().getBytes();
out.write(b);
}
}
46
// TimeClient
import java.net.*;
import java.io.*;
public class TimeClient {
public static void main (String args[])
throws IOException {
Socket server = new Socket
("localhost",1234);
System.out.println("Connected to
"+server.getInetAddress());
InputStream in = server.getInputStream();
byte b[] = new byte[100];
int num = in.read(b);
String date = new String(b);
System.out.println("Server said: "+date);
}
}
47