This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
What is the Internet?
• Hosts or end-systems• PCs, workstations, servers
• PDAs, phones, toasters
• Communication links• fiber, copper, radio, satellite
• Routers• forward packets
• Protocols• TCP, IP, HTTP, FTP, SMTP
• Internet• Network of networks
• Applications• WWW, email, games, e-
commerce, database, voting, file (MP3) sharing
local ISP
companynetwork
regional ISP
router workstation
servermobile
2
Network Equipment
Ethernet Switches
Wiring Closet
Ethernet
3
Network Equipment
Wireless LAN base station
Cisco Routers
Cable Modem
4
What is a Protocol?
Human Protocol
Hi
Hi
Got thetime?
2:00
connection req.
connectionreply.
<file>
time
Network Protocol
5
Network Structure
• Core Networks• Routers• Network of networks
• End systems (hosts):• Run application programs• E.g., WWW, email• At “edge of network”
• How is data transferred through networks?• Routing• Forwarding
6
Delays and Routes in the Internet
1 cs-gw (128.119.240.254) 1 ms 1 ms 2 ms2 border1-rt-fa5-1-0.gw.umass.edu (128.119.3.145) 1 ms 1 ms 2 ms3 cht-vbns.gw.umass.edu (128.119.3.130) 6 ms 5 ms 5 ms4 jn1-at1-0-0-19.wor.vbns.net (204.147.132.129) 16 ms 11 ms 13 ms 5 jn1-so7-0-0-0.wae.vbns.net (204.147.136.136) 21 ms 18 ms 18 ms 6 abilene-vbns.abilene.ucaid.edu (198.32.11.9) 22 ms 18 ms 22 ms7 nycm-wash.abilene.ucaid.edu (198.32.8.46) 22 ms 22 ms 22 ms8 62.40.103.253 (62.40.103.253) 104 ms 109 ms 106 ms9 de2-1.de1.de.geant.net (62.40.96.129) 109 ms 102 ms 104 ms10 de.fr1.fr.geant.net (62.40.96.50) 113 ms 121 ms 114 ms11 renater-gw.fr1.fr.geant.net (62.40.103.54) 112 ms 114 ms 112 ms12 nio-n2.cssi.renater.fr (193.51.206.13) 111 ms 114 ms 116 ms13 nice.cssi.renater.fr (195.220.98.102) 123 ms 125 ms 124 ms14 r3t2-nice.cssi.renater.fr (195.220.98.110) 126 ms 126 ms 124 ms15 eurecom-valbonne.r3t2.ft.net (193.48.50.54) 135 ms 128 ms 133 ms16 194.214.211.25 (194.214.211.25) 126 ms 128 ms 126 ms17 * * *18 * * *19 fantasia.eurecom.fr (193.55.113.142) 132 ms 128 ms 136 ms
Most UNIX servers run the daytime service on TCP port 13.
cobalt> telnet holly.cs.rit.edu 13 Trying 129.21.30.35... Connected to holly. Escape character is '^]'. Fri Feb 6 08:33:44 1998 Connection closed by foreign host. It is easy to write a Java daytime client. All the program needs to do is to establish a TCP connection on port 13 of a remote host.
A TCP style connection is made using the Socket class.
25
Class Socket
// Constructors (partial list)public Socket()public Socket(InetAddress address, int port);public Socket(String host, int port);
// Methods (partial list)public void close();
public InetAddress getInetAddress(); public int getLocalPort();
public InputStream getInputStream();public OutputStream getOutputStream();
public class DayTimeServer { public static void main(String argv[]) { try { ServerSocket listen = new ServerSocket(0); System.out.println("Listening on port: "+listen.getLocalPort());
The output from the daytime server looks like this: kiev> java DayTimeServer Listening on port: 36109 Socket[addr=cobalt/129.21.37.176,port=32875,localport=36109] Socket[addr=localhost/127.0.0.1,port=36112,localport=36109]
The client output looks like this:
cobalt> telnet kiev 36109 Trying 129.21.38.145... Connected to kiev. Escape character is '^]'. Fri Feb 06 09:53:00 EST 1998 Connection closed by foreign host.
31
Problem: Client/Server
• Write a client/server application in which the client sends a radius, and the server computes the area and sends it back to the client.
• Write a client program that reads a Web page specified by a given URL (Uniform Resource Locator).• Use class java.net.URL.
32
Multi-Threaded Servers
• It is quite easy, and natural in Java, to make a server multi-threaded.
• In a multi-threaded server a new thread is created to handle each request.
• Clearly for a server such as the daytime server this is not necessary, but for an FTP server this is almost required.
• Why?
• The code for the multi-threaded version of the server consists of a new class called Connection.
• An instance of this class handles the clients request.
public class TDayTimeServer { public static void main(String argv[]) { try { ServerSocket listen = new ServerSocket(0); System.out.println("Listening on: "+listen.getLocalPort());
class Connection extends Thread { protected Socket clnt;
public Connection(Socket sock) { clnt = sock; }
public void run() { Date today = new Date(); try { PrintWriter out = new PrintWriter(clnt.getOutputStream(), true); out.println(today); clnt.close(); } catch (IOException e) {} }
}
35
Multi Servers and Clients
• We can also create a new server thread listening to the port every time.
• See MTS.java and MTSclient.java
36
Datagrams
• Datagram packets are used to implement a connectionless, packet based, delivery service.
• Each message is routed from one machine to another based solely on information contained within that packet.
• Multiple packets sent from one machine to another might be routed differently, and might arrive in any order.
• Packets may be lost or duplicated during transit.
• The class DatagramPacket represents a datagram in Java.
37
Class DatagramPacket
//Constructors// For receiving a packet:public DatagramPacket(byte ibuf[], int ilength);// For sending a packet (need address information):public DatagramPacket( byte ibuf[], int ilength, InetAddress iaddr, int iport);
• This class represents a socket for sending and receiving datagram packets.
• Addressing information for outgoing packets is contained in the packet header.
• A socket that is used to read incoming packets must be bound to an address (sockets that are used for sending must be bound as well, but in most cases it is done automatically).
• There is no special datagram server socket class.• Since packets can be lost, the ability to set timeouts is
public class UdpEchoServer { static int echoPort = 7000; static int msgLen = 1024; public static void main(String args[]) { try { DatagramSocket sock = new DatagramSocket(echoPort); DatagramPacket p, reply; byte msg[] = new byte[msgLen]; p = new DatagramPacket(msg,msgLen);
for (;;) { sock.receive(p); System.out.println(p.getAddress()); reply = new DatagramPacket(p.getData(), p.getLength(), p.getAddress(), p.getPort()); sock.send(reply); } } catch (Exception e) {} }}
43
Problem: UDPDayTime Server and Client
• Write a program that implements a DayTime Server and Client using UDP connections.
• How can I convert my previous tic-tac-toe program to a networked version?