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

Slides:



Advertisements
Similar presentations
Protocol layers and Wireshark Rahul Hiran TDTS11:Computer Networks and Internet Protocols 1 Note: T he slides are adapted and modified based on slides.
Advertisements

CSCI Java Networking1 Java Net Classes ClassDescription DatagramPacketThis class represents a datagram packet. DatagramSocketThis class represents.
Summer Workshop on Cyber Security Computer Networks Security (Part 1) Dr. Hamed Mohsenian-Rad University of California at Riverside and Texas Tech University.
2: Application Layer 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
Socket Programming.
User Datagram Protocol. Introduction UDP is a connectionless transport protocol, i.e. it doesn't guarantee either packet delivery or that packets arrive.
Prepared By E. Musa Alyaman1 User Datagram Protocol (UDP) Chapter 5.
1 Java Networking – Part I CS , Spring 2008/9.
Introduction1-1 Introduction to Computer Networks Our goal:  get “feel” and terminology  more depth, detail later in course  approach:  use Internet.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
Networking Support In Java 2 Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Networking Overview February 2, /2/2004 Assignments Due – Homework 0 Due – Reading and Warmup questions Work on Homework 1.
Lecture 11 Java Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Joonbok Lee.
Client/Server In Java An Introduction to TCP/IP and Sockets.
Networking Support In Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Networking Support In Java 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
What’s the Internet: “nuts and bolts” view
1: Introduction1 Part I: Introduction Goal: r get context, overview, “feel” of networking r more depth, detail later in course r approach: m descriptive.
Networking in Java Representation and Management of Data on the Internet.
Process-to-Process Delivery:
CP476 Internet ComputingCh.1 # 1 Lecture 2. A Brief Introduction to the Internet The objective is to understand The history of Internet What the Internet.
Babak Esfandiari (based on slides by Qusay Mahmoud)
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
Network Programming OSI Model Client-server programming.
Multicast Sockets What is a multicast socket?
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
CS 3214 Computer Systems Godmar Back Lecture 23. Announcements Project 5 due Dec 8 Exercise 10 handed out Exercise 11 coming before Thanksgiving CS 3214.
VIII. UDP Datagrams and Sockets. The User Datagram Protocol (UDP) is an alternative protocol for sending data over IP that is very quick, but not reliable:
World-wide-web o Tim Berners-Lee implements his childhood Enquire “2.0” o It took off because it could do hypertext on the internet! o 3 crucial components:
DBI Representation and Management of Data on the Internet.
Introduction 1-1 “Real” Internet delays and routes  What do “real” Internet delay & loss look like?  Traceroute program: provides delay measurement from.
1 CSCD 330 Network Programming Winter 2015 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 6 Application.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
1 A TCP/IP Application Programming Perspective Chris Greenhalgh G53ACC.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
Java Sockets Programming
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
What is a Network? Computer network Computer network a set of computers using common protocols to communicate over connecting transmission media. a set.
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/11) Java Sockets and Simple Networking Joel Adams and Jeremy Frens.
12/5/2015.net 1 system.net Contains any network functionallity you would need in c# Several sub namespaces exists to allow for more fined control –System.Net.Sockets.
By Vivek Dimri. Basic Concepts on Networking IP Address – Protocol – Ports – The Client/Server Paradigm – Sockets The Java Networking Package – The InetAddress.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
1 COMP 431 Internet Services & Protocols Client/Server Computing & Socket Programming Jasleen Kaur February 2, 2016.
Java Programming II Java Network (I) Java Programming II.
1 CSCD 330 Network Programming Winter 2016 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 6 Application.
UDP User Datagram Protocol. About the UDP A commonly used transport protocol Does not guarantee either packet delivery or order The packets may travel.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Introduction and Overview of Network and Telecommunications.
Network Programming. These days almost all devices.
Network Programming Communication between processes Many approaches:
Java.net CS-328 Dick Steflik.
Object-Orientated Analysis, Design and Programming
Introduction and Overview of Network and Telecommunications
CS 3214 Computer Systems Networking.
Slides taken from: Computer Networking by Kurose and Ross
MCA – 405 Elective –I (A) Java Programming & Technology
CS 3214 Computer Systems Networking.
Introduction and Overview of Network and Telecommunications (contd.)
An Introduction to TCP/IP and Sockets
Network Programming Introduction
CSCD 330 Network Programming
Process-to-Process Delivery:
Networking.
TCP/IP Protocol Suite: Review
Process-to-Process Delivery: UDP, TCP
Presentation 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, , games, e- commerce, database, voting, file (MP3) sharing local ISP company network regional ISP router workstation server mobile

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 Got the time? 2:00 connection req. connection reply. time Network Protocol

5 Network Structure Core Networks Routers Network of networks End systems (hosts): Run application programs E.g., WWW, At “edge of network” How is data transferred through networks? Routing Forwarding

6 Delays and Routes in the Internet 1 cs-gw ( ) 1 ms 1 ms 2 ms 2 border1-rt-fa5-1-0.gw.umass.edu ( ) 1 ms 1 ms 2 ms 3 cht-vbns.gw.umass.edu ( ) 6 ms 5 ms 5 ms 4 jn1-at wor.vbns.net ( ) 16 ms 11 ms 13 ms 5 jn1-so wae.vbns.net ( ) 21 ms 18 ms 18 ms 6 abilene-vbns.abilene.ucaid.edu ( ) 22 ms 18 ms 22 ms 7 nycm-wash.abilene.ucaid.edu ( ) 22 ms 22 ms 22 ms ( ) 104 ms 109 ms 106 ms 9 de2-1.de1.de.geant.net ( ) 109 ms 102 ms 104 ms 10 de.fr1.fr.geant.net ( ) 113 ms 121 ms 114 ms 11 renater-gw.fr1.fr.geant.net ( ) 112 ms 114 ms 112 ms 12 nio-n2.cssi.renater.fr ( ) 111 ms 114 ms 116 ms 13 nice.cssi.renater.fr ( ) 123 ms 125 ms 124 ms 14 r3t2-nice.cssi.renater.fr ( ) 126 ms 126 ms 124 ms 15 eurecom-valbonne.r3t2.ft.net ( ) 135 ms 128 ms 133 ms ( ) 126 ms 128 ms 126 ms 17 * * * 18 * * * 19 fantasia.eurecom.fr ( ) 132 ms 128 ms 136 ms Traceroute in Unix

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 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 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 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 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 The TCP/IP Protocol Suite ARPRARP Hardware Interface ICMPIGMPIP TCPUDP User Process User Process User Process User Process application transport network link

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: Who assigns the IP addresses? InterNIC, IANA, ICANN

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 “Good” path: Typically means minimum cost path Other def’s possible

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 Internet Service Provider (ISP) Sprint US backbone network

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 Connection-oriented Transfer Create Socket Accept Read/Write Create Socket Connect Read/Write Server Client Connection Establishment Communication

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

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 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 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 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 Daytime Service Most UNIX servers run the daytime service on TCP port 13. cobalt> telnet holly.cs.rit.edu 13 Trying Connected to holly. Escape character is '^]'. Fri Feb 6 08:33: 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 int getPort(); public String toString();

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 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 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 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 DayTimeServer in Action The output from the daytime server looks like this: kiev> java DayTimeServer Listening on port: Socket[addr=cobalt/ ,port=32875,localport=36109] Socket[addr=localhost/ ,port=36112,localport=36109] The client output looks like this: cobalt> telnet kiev Trying 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.

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 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 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); // 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 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 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 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 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 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 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?