1 A TCP/IP Application Programming Perspective Chris Greenhalgh G53ACC.

Slides:



Advertisements
Similar presentations
Transport Layer3-1 Transport Overview and UDP. Transport Layer3-2 Goals r Understand transport services m Multiplexing and Demultiplexing m Reliable data.
Advertisements

Jan Java Networking UDP Yangjun Chen Dept. Business Computing University of Winnipeg.
Network Programming Chapter 11 Lecture 6. Networks.
Computer Communication Digital Communication in the Modern World Transport Layer Multiplexing, UDP
Chapter 3: Transport Layer
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.
Transport Layer3-1 Transport Layer Our goals: r understand principles behind transport layer services: m multiplexing/demultipl exing m reliable data transfer.
Networking Support In Java 2 Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Java Socket Support Presentation by: Lijun Yuan Course Number: cs616.
Lecture 8 Chapter 3 Transport Layer
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.
Networking Support In Java 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
8-1 Transport Layer Our goals: r understand principles behind transport layer services: m multiplexing/demultipl exing m reliable data transfer m flow.
Process-to-Process Delivery:
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
Babak Esfandiari (based on slides by Qusay Mahmoud)
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket 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.
Review: –What is AS? –What is the routing algorithm in BGP? –How does it work? –Where is “policy” reflected in BGP (policy based routing)? –Give examples.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
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:
Data Communications and Computer Networks Chapter 3 CS 3830 Lecture 12 Omar Meqdadi Department of Computer Science and Software Engineering University.
Network LayerII-1 RSC Part III: Transport Layer 1. Basic Concepts Redes y Servicios de Comunicaciones Universidad Carlos III de Madrid These slides are,
 TCP (Transport Control Protocol) is a connection-oriented protocol that provides a reliable flow of data between two computers.  TCP/IP Stack Application.
Transport Layer 3-1 Chapter 3 Transport Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012 Part.
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Chapter 3 Transport Layer
Socket Programming in Java CS587x Lecture 4 Department of Computer Science Iowa State University.
Transport Layer1 Ram Dantu (compiled from various text books)
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
Java Sockets Programming
1 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
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.
Overview of TCP/IP protocols –Application layer (telnet, ssh, http, ftp, etc) The things that we use daily. –Transport layer (TCP, UDP) Allows processes.
Transport Layer 3-1 Chapter 3 Outline r 3.1 Transport-layer services r 3.2 Multiplexing and demultiplexing r 3.3 Connectionless transport: UDP.
Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
MULTIPLEXING/DEMULTIPLEXING, CONNECTIONLESS TRANSPORT.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Java Programming II Java Network (I) Java Programming II.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
UDP User Datagram Protocol. About the UDP A commonly used transport protocol Does not guarantee either packet delivery or order The packets may travel.
Data Communications and Networks Chapter 6 – IP, UDP and TCP ICT-BVF8.1- Data Communications and Network Trainer: Dr. Abbes Sebihi.
Transport Layer3-1 Chapter 3: Transport Layer Our goals: r understand principles behind transport layer services: m multiplexing/demultipl exing m reliable.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
1 Network Communications A Brief Introduction. 2 Network Communications.
Introduction 1-1 source application transport network link physical HtHt HnHn M segment HtHt datagram destination application transport network link physical.
Network Programming. These days almost all devices.
Network Programming Communication between processes Many approaches:
Java.net CS-328 Dick Steflik.
Socket Programming Ameera Almasoud
Object-Orientated Analysis, Design and Programming
MCA – 405 Elective –I (A) Java Programming & Technology
NETWORK PROGRAMMING CNET 441
An Introduction to TCP/IP and Sockets
Network Programming Introduction
Networking.
NETWORK PROGRAMMING CNET 441
Java Socket Programming
Transport Layer Our goals:
Presentation transcript:

1 A TCP/IP Application Programming Perspective Chris Greenhalgh G53ACC

2 Contents Overview IP layer, IP addresses and API Transport layer –TCP service, API and examples –UDP service, API and examples Books: Comer ch.17, 18, 24 & 25 (part), (part); Farley ch. 2

3 Overview The TCP/IP Internet Protocols –Internet = Inter-Network Universal service: the illusion of a single network Internal details Concept (transparency:-) Comer Fig. 17.3

4 TCP/IP reference model IEEE802 Ethernet, WiFi, … IP TCP, UDP Comer Fig. 17.4

5 IP: Internet layer Deals with end-to-end communication between hosts on the Internet Identifies hosts using IP addresses –One per host network interface –Globally unique But only on the Internet proper See also NAT & private IP addresses (later notes)

6 IP v.4 addresses: 32 bits Normally written in dotted decimal notation: Comer Fig. 18.3

7 One IP address per network interface (e.g.) Host (computer) Comer Fig. 18.9

8 Special IP v.4 addresses Network = class bit(s) and prefix Comer Fig. 18.1, 18.8

9 Address ranges, masks and CIDR addresses (e.g.) CIDR notation NB first 28 bits are 1s NB bit-wise AND with Mask value = prefix Comer Fig. 18.7

10 Java API: java.net.InetAddress Instance = single IP address and/or DNS hostname –(see later notes for more detail of DNS) API Excerpts: public class InetAddress { // host may be dotted IP or DNS name public static InetAddress getByName(String host) throws UnknownHostException; public static InetAddress getLocalHost() throws UnknownHostException; public String getHostAddress(); public String getHostName(); public boolean isMulticastAddress(); }

11 Transport Layer Allows multiple end-points per host Supports different qualities of service (QOS) –Connection oriented (stream) service Transport Control Protocol (TCP) –Connectionless (datagram) service User Datagram Protocol (UDP)

12 Transport Control Protocol (TCP) Specified in RFC793 Service: –Connection between two processes –Reliable delivery –Bi-directional –With flow and congestion control –e.g. used for remote login, , HTTP Acts as a “pipe” between two endpoints.

13 Connection-Oriented Services C.f. the telephone network –Pick up the phone = initiate a connection –Dial number = specify address of other party –Recipient answers phone = connection is made –Speak = data is transferred in both directions –One or both parties hang up = break connection

14 Ports Each transport protocol has a set of ‘ports’ on the network –TCP & UDP have 16 bit port numbers ( ) Transport level protocols identify source & destination port numbers –Network level protocol (IP) identifies source and destination host Application can be bound to one particular IP and one particular port, or to any local IP and one particular port

15 Ports example Process A Process B Process C Host= Network Packet Host Port# 4

16 Special port numbers Fixed port numbers allocated by Internet Assigned Numbers Authority (IANA) –E.g. HTTP, tcp port 80 “Low” port-numbers typically reserved for standard services –E.g. <1024 Or application may obtain “next unused” local port number from OS

17 Sockets A socket –is an endpoint of communication Created and used within an application –is bound to a particular port –has a type which specifies the type of communications it supports E.g. TCP (stream), UDP (datagram) –communicates with sockets of the same type May be linked to one specific socket, e.g. TCP, or may be able to communicate with multiple other sockets, e.g. TCP server socket or UDP socket.

18 Java API: java.net.ServerSocket Used by server API Excerpts: public class ServerSocket { // port 0 => next unused local port public ServerSocket(int port) throws java.io.IOException; public InetAddress getInetAddress(); public int getLocalPort(); public Socket accept() throws java.io.IOException; public void close() throws java.io.IOException; }

19 Java server skeleton import java.net.Socket; import java.net.ServerSocket; import java.io.IOException; public class ReverseServerTCP { public static void main(String [] args) { try { int port = Integer.parseInt(args[0]); ServerSocket s = new ServerSocket(port); while (true) { Socket c = s.accept(); // handle client... } } catch (IOException e) { /*... */ } }

20 Java API: java.net.Socket Used by client and server (once connected) API Excerpts: public class Socket { // constructors only used by client public Socket(String host, int port) throws UnknownHostException, IOException; public Socket(InetAddress host, int port) throws IOException; public InetAddress getInetAddress(); public int getPort(); public java.io.InputStream getInputStream() throws IOException; public java.io.OutputStream getOutputStream() throws IOException; public void close() throws IOException; }

21 Sample client (and full server) See ACCExamples –tcp/ReverseClientTCP.java –tcp/ReverseServerTCP.java Note: relies on java.io framework - TCP just moves a sequence of bytes –Use raw streams and/or BufferedInput/OutputStreams if you want to exchange particular byte sequences –Use Reader/Writer if you want to exchange text –Use DataInput/DataOutput if you want to marshall java primitive types –Use ObjectInputStream/ObjectOutputStream if you want to marshall Java Serializable objects

22 TCP Client and server structure Server –new ServerSocket(port) –serverSkt.accept() returns new Socket –skt.getInputStream read, etc. –skt.getOutputStream write, etc. –skt.close() Client –new Socket(host, port) –skt.getOutputStream write, etc. –skt.getInputStream read, etc. –skt.close() connect request response

23 Multi-threaded server execution Main thread accept() Client-specific thread(s) ServerSocket client Socket(s) new Thread().start() [UNIX: fork()]

24 User Datagram Protocol (UDP) Specified in RFC 768 Connectionless Datagrams can be transmitted to –A single machine –A group of machines (multicast or broadcast) Bidirectional Unreliable Maximum payload 64Kbytes (65535 bytes)

25 Connectionless Services analogy Can be compared to the postal service –A letter is put into an envelope (data into a datagram) –The envelope is addressed to the recipient –The envelope is put in the post box and enters the delivery system –The envelope arrives (hopefully) at the destination

26 Connectionless Services Unreliable –May never arrive –No indication if the delivery is successful Unordered –May arrive in a different order (a variety of possible routes) Rarely (but occasionally) duplicated Error-checked (corrupt packets usually detected and discarded)

27 UDP and TCP Uses sockets API for both UDP and TCP –stream type for TCP –datagram type for UDP Uses port numbers for both –but UDP port 53 is NOT same as TCP port 53

28 UDP uses Very simple request/response protocols –small maximum size, e.g. DNS No 3-way handshake delay (cf. TCP) No reliability overhead/retransmit delay –E.g. for streamed audio, video But: –no flow control, congestion control (can be added, but quite tricky and more overhead again)

29 Java API: java.net.DatagramSocket Used by client and server API Excerpts: public class DatagramSocket { public DatagramSocket() throws SocketException; public DatagramSocket(int port) throws SocketException; public int getLocalPort(); public void setSoTimeout(int timeout) throws SocketException; public void send(DatagramPacket p) throws IOException; public void receive(DatagramPacket p) throws IOException; public void close(); }

30 Java API: java.net.DatagramPacket Instance combines: –Application data - byte array –Actual size used (number of bytes) –Source/destination InetAddress –Source/destination port Source if received, destination if sending API Excerpts: see over

31 public class DatagramPacket { public DatagramPacket(byte[] buf, int offset, int length); public DatagramPacket(byte[] buf, int length); public DatagramPacket(byte[] buf, int offset, int length, InetAddress address, int port); public DatagramPacket(byte[] buf, int length, InetAddress address, int port); public InetAddress getAddress(); public int getPort(); public byte[] getData(); public int getLength(); public void setAddress(InetAddress iaddr); public void setPort(int iport); public void setData(byte[] buf); public void setData(byte[] buf, int offset, int length); public void setLength(int length); }

32 Sample UDP client and server See ACCExamples –unicast/ReverseClientUnicast.java –unicast/ReverseServerUnicast.java Note: can still use java.io framework - UDP just moves an array of bytes (<=65535) –Can get/set bytes directly –Can use ByteArrayInput/OutputStream to read/write bytes as streams Can combine with DataInput/Output or ObjectInput/OutputStream as used with TCP

33 UDP Client and server structure Server –new DatagramSocket() –loop: new DatagramPacket() skt.receive(pkt) new DatagramPacket() skt.send(pkt) –GC DatagramSocket Client –new DatagramSocket() –work: new DatagramPacket() skt.send(pkt) new DatagramPacket() skt.receive(pkt) –GC DatagramSocket request response