Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 What is the Internet? Hosts or end-systems PCs, workstations, servers PDAs, phones, toasters Communication links fiber, copper, radio, satellite Routers.

Similar presentations


Presentation on theme: "1 What is the Internet? Hosts or end-systems PCs, workstations, servers PDAs, phones, toasters Communication links fiber, copper, radio, satellite Routers."— Presentation transcript:

1 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 company network regional ISP router workstation server mobile

2 2 Network Equipment Ethernet Switches Wiring Closet Ethernet

3 3 Network Equipment Wireless LAN base station Cisco Routers Cable Modem

4 4 What is a Protocol? Human Protocol Hi Got the time? 2:00 connection req. connection reply. time Network Protocol

5 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 6 Delays and Routes in the Internet 1 cs-gw (128.119.240.254) 1 ms 1 ms 2 ms 2 border1-rt-fa5-1-0.gw.umass.edu (128.119.3.145) 1 ms 1 ms 2 ms 3 cht-vbns.gw.umass.edu (128.119.3.130) 6 ms 5 ms 5 ms 4 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 ms 7 nycm-wash.abilene.ucaid.edu (198.32.8.46) 22 ms 22 ms 22 ms 8 62.40.103.253 (62.40.103.253) 104 ms 109 ms 106 ms 9 de2-1.de1.de.geant.net (62.40.96.129) 109 ms 102 ms 104 ms 10 de.fr1.fr.geant.net (62.40.96.50) 113 ms 121 ms 114 ms 11 renater-gw.fr1.fr.geant.net (62.40.103.54) 112 ms 114 ms 112 ms 12 nio-n2.cssi.renater.fr (193.51.206.13) 111 ms 114 ms 116 ms 13 nice.cssi.renater.fr (195.220.98.102) 123 ms 125 ms 124 ms 14 r3t2-nice.cssi.renater.fr (195.220.98.110) 126 ms 126 ms 124 ms 15 eurecom-valbonne.r3t2.ft.net (193.48.50.54) 135 ms 128 ms 133 ms 16 194.214.211.25 (194.214.211.25) 126 ms 128 ms 126 ms 17 * * * 18 * * * 19 fantasia.eurecom.fr (193.55.113.142) 132 ms 128 ms 136 ms Traceroute in Unix

7 7 Air Travel Organization ticket (purchase) baggage (check) gates (load) runway takeoff airplane routing ticket (complain) baggage (claim) gates (unload) runway landing airplane routing Is there a way to organize structure of network?

8 8 Internet Protocol Stack Application: supporting network applications ftp, smtp, http Transport: host-host data transfer tcp, udp Network: routing of datagrams from source to destination ip, routing protocols Link: data transfer between neighboring network elements ppp, ethernet Physical: bits “on the wire” application transport network link physical

9 9 Internet Layering application transport network link physical application transport network link physical application transport network link physical application transport network link physical network link physical

10 10 Data Communication application transport network link physical application transport network link physical application transport network link physical application transport network link physical network link physical data

11 11 Protocol Layering and Data Each layer takes data from above adds header information to create new data unit passes new data unit to layer below application transport network link physical application transport network link physical source destination M M M M H t H t H n H t H n H l M M M M H t H t H n H t H n H l message segment frame

12 12 The TCP/IP Protocol Suite ARPRARP Hardware Interface ICMPIGMPIP TCPUDP User Process User Process User Process User Process application transport network link

13 13 IP: Internet Protocol IP provides an unreliable, connectionless, datagram delivery service. Addressing IP addresses are 32-bit numbers and are divided into two components: the host address and the network address. Example: 129.21.38.169 Who assigns the IP addresses? InterNIC, IANA, ICANN

14 14 Routing Graph abstraction for routing algorithms: Graph nodes are routers Graph edges are physical links Link cost: delay, $ cost, or congestion level Goal: determine “good” path (sequence of routers) thru network from source to dest. Routing protocol A E D CB F 2 2 1 3 1 1 2 5 3 5 “Good” path: Typically means minimum cost path Other def’s possible

15 15 TCP: Transmission Control Protocol TCP provides a connection-oriented, reliable, byte stream service (RFC793). A stream of 8-bit bytes is exchanged across a TCP connection. TCP uses congestion control via congestion windows and acknowledgments. TCP uses protocol port numbers to identify the ultimate destination within a machine.

16 16 Internet Service Provider (ISP) Sprint US backbone network

17 17 Socket Programming In the early 80s, UCB developed the UNIX BSD versions supporting TCP/IP. Berkeley sockets are one of the most widely used communication APIs. A socket is an object from which messages are sent and received. Two types of transfer connection-oriented vs. connectionless The “Network”

18 18 Connection-oriented Transfer Create Socket Accept Read/Write Create Socket Connect Read/Write Server Client Connection Establishment Communication

19 19 Connectionless Transfer Create Socket Read/Write Create Socket Read/Write Server Client Communication

20 20 java.net.* Classes InetAddress Socket ServerSocket DatagramSocket DatagramPacket Exceptions –BindException –ConnectException –MalformedURLException –NoRouteToHostException –ProtocolException –SocketException –UnknownHostException –UnknownServiceException The java.net package provides networking support.

21 21 Class InetAddress public byte[] getAddress(); public static InetAddress[] getAllByName(String host); public static InetAddress getByName(String host); public String getHostAddress(); public String getHostName(); public static InetAddress getLocalHost(); This class represents an Internet Protocol (IP) address. Applications should use the methods getLocalHost(), getByName(), or getAllByName() to create a new InetAddress instance.

22 22 HostInfo.java import java.net.*; import java.io.*; import java.util.*; public class HostInfo { public static void main(String argv[]) { InetAddress ipAddr; try { ipAddr = InetAddress.getLocalHost(); System.out.println("This is "+ipAddr); } catch (UnknownHostException e) { System.out.println("Unknown host"); } Can you write a program that identifies the host name and IP address of a specified host?

23 23 Resolver.java import java.net.*; import java.io.*; import java.util.*; public class Resolver { public static void main( String args[] ) { InetAddress ipAddr; try { ipAddr = InetAddress.getByName( args[0] ); System.out.print("IP address = “ + ipAddr + "\n"); } catch (UnknownHostException e){ System.out.println("Unknown host"); }

24 24 Daytime Service 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 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 int getPort(); public String toString();

26 26 DayTimeClient.java import java.net.*; import java.io.*; import java.util.*; public class DayTimeClient { static int dayTimePort = 13; public static void main(String argv[]) { try { Socket sock = new Socket(argv[0], dayTimePort); BufferedReader din = new BufferedReader( new InputStreamReader( sock.getInputStream() )); String rTime = din.readLine(); System.out.println(rTime); sock.close(); } catch (exception e) {} }

27 27 A Java Daytime Server It is easy to create a daytime server in Java. The only real problem is that your Java server will not be able to use port 13. The server version of the program will use a ServerSocket to communicate with a client. A ServerSocket will open a TCP port and wait for a connection. Once a request is detected, a new port will be created, and the connection will be established between the client's source port and this new port. Most servers listen for requests on a particular port, and then service that request on a different port. This makes it easy for the server to accept and service requests at the same time.

28 28 Class ServerSocket // Constructors (partial list) public ServerSocket(int port); public ServerSocket(int port, int count); // Methods (partial list) public Socket accept(); public void close(); public InetAddress getInetAddress(); public int getLocalPort(); public String toString();

29 29 DayTimeServer import java.net.*; import java.io.*; import java.util.*; public class DayTimeServer { public static void main(String argv[]) { try { ServerSocket listen = new ServerSocket(0); System.out.println("Listening on port: "+listen.getLocalPort()); for(;;) { Socket clnt = listen.accept(); System.out.println(clnt.toString()); PrintWriter out = new PrintWriter(clnt.getOutputStream(), true); out.println(new Date()); clnt.close(); } } catch(Exception e) {}}}

30 30 DayTimeServer in Action 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 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 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.

33 33 TDayTimeServer.java import java.net.*; import java.io.*; import java.util.*; public class TDayTimeServer { public static void main(String argv[]) { try { ServerSocket listen = new ServerSocket(0); System.out.println("Listening on: "+listen.getLocalPort()); while(true) { Socket clnt = listen.accept(); System.out.println(clnt.toString()); Connection c = new Connection(clnt); c.start(); } catch(Exception e) { System.out.println("Server terminated"); }

34 34 Connection.java import java.net.*; import java.io.*; import java.util.*; 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 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 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 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); // Methods public synchronized InetAddress getAddress(); public synchronized int getPort(); public synchornized byte[] getData(); int getLength(); void setAddress(InetAddress iaddr); void setPort(int iport); void setData(byte ibuf[]); void setLength(int ilength);

38 38 Class DatagramSocket 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 important.

39 39 Class DatagramSocket // Constructors DatagramSocket() DatagramSocket(int port) DatagramSocket(int port, InetAddress iaddr) // Methods void receive(DatagramPacket p) void send(DatagramPacket p) void setSoTimeout(int timeout) void close() InetAddress getLocalAddress() int getLocalPort() int getSoTimeout()

40 40 Echo Services A common network service is an echo server. An echo server simply sends packets back to the sender. A client creates a packet, sends it to the server, and waits for a response. Echo services can be used to test network connectivity and performance.

41 41 UDPEchoClient.java import java.net.*; import java.io.*; import java.util.*; public class UDPEchoClient { static int echoPort = 7000; static int msgLen = 16; static int timeOut=1000; public static void main(String args[]) { try { DatagramSocket sock = new DatagramSocket(); DatagramPacket pak; byte msg[] = new byte[msgLen]; InetAddress echoHost = InetAddress.getByName(args[0]); pak = new DatagramPacket(msg,msgLen,echoHost,echoPort); sock.send(pak); sock.setSoTimeout(timeOut); sock.receive(pak); } catch (InterruptedIOException e) {System.out.println("Timeout");} catch (Exception e) {} }

42 42 UDPEchoServer.java import java.net.*; import java.io.*; import java.util.*; 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 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?


Download ppt "1 What is the Internet? Hosts or end-systems PCs, workstations, servers PDAs, phones, toasters Communication links fiber, copper, radio, satellite Routers."

Similar presentations


Ads by Google