Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE524: Lecture 3 Application layer.

Similar presentations


Presentation on theme: "CSE524: Lecture 3 Application layer."— Presentation transcript:

1 CSE524: Lecture 3 Application layer

2 Administrative CSE524 e-mail list Homework assignments
Homework #1 Access to machine resources for programming project and assignments Get yourself an account Use class laboratory

3 Where we're at.... Internet architecture and history
Internet in a nutshell Packet trace example of protocols in action Rest of the course Application, Transport, Network, Data-link, Physical layers

4 This class Application layer Application layer overview and functions
Programming application protocols BSD Socket API Java Socket API Java high-level networking API Specific application protocols HTTP FTP DNS SMTP

5 Application layer overview
Application: communicating sets of distributed processes e.g., , Web, P2P file sharing, instant messaging running in end systems (hosts) exchange messages to implement application Application-layer protocols one “piece” of an app define messages exchanged by apps and actions taken use communication services provided by lower layer protocols (TCP, UDP) application transport network data link physical

6 Application layer functions
Applications Implement desired functionality within application protocols when no underlying network service provides support Mail, Web, News, P2P, etc…. Other functions Security (S/MIME, PGP, S-HTTP) Delivery semantics (multicast overlays, anycast) Reliable data transfer (reliable multicast, reliable UDP) Quality of service (QoS overlays, scheduling) Congestion control (Non-TCP applications) Flow control (Non-TCP applications) Naming (DNS, URLs) Routing (overlays) Functionality that is common rolled into libraries and “middleware”

7 Application protocols define
How to implement functions Types of messages exchanged, eg, request & response messages Syntax of message types: what fields in messages & how fields are delineated Semantics of the fields, ie, meaning of information in fields Rules for when and how processes send & respond to messages Public-domain protocols: defined in RFCs allows for interoperability eg, HTTP, SMTP Proprietary protocols: eg, KaZaA

8 Client-server paradigm
initiates contact with server (“speaks first”) typically requests service from server, Web: client implemented in browser; in mail reader Typical network app has two pieces: client and server application transport network data link physical reply request Server: provides requested service to client e.g., Web server sends requested Web page, mail server delivers

9 Processes communicating across network
process sends/receives messages to/from its socket socket analogous to door sending process shoves message out door sending process asssumes transport infrastructure on other side of door which brings message to socket at receiving process process TCP with buffers, variables socket host or server process TCP with buffers, variables socket host or server controlled by app developer Internet controlled by OS API: (1) choice of transport protocol; (2) ability to fix a few parameters (lots more on this later)

10 Addressing processes:
For a process to receive messages, it must have an identifier Every host has a unique 32-bit IP address Q: does the IP address of the host on which the process runs suffice for identifying the process? Answer: No, many processes can be running on same host Identifier includes both the IP address and port numbers associated with the process on the host. Example port numbers: HTTP server: 80 Mail server: 25

11 What transport service does an app need?
Data loss some apps (e.g., audio) can tolerate some loss other apps (e.g., file transfer, telnet) require 100% reliable data transfer Bandwidth some apps (e.g., multimedia) require minimum amount of bandwidth to be “effective” other apps (“elastic apps”) make use of whatever bandwidth they get Timing some apps (e.g., Internet telephony, interactive games) require low delay to be “effective”

12 Transport service requirements of common apps
Application file transfer Web documents real-time audio/video stored audio/video interactive games instant messaging Time Sensitive no yes, 100’s msec yes, few secs yes and no Data loss no loss loss-tolerant Bandwidth elastic audio: 5kbps-1Mbps video:10kbps-5Mbps same as above few kbps up

13 Recall Internet transport protocol services
TCP service: connection-oriented: setup required between client and server processes reliable transport between sending and receiving process flow control: sender won’t overwhelm receiver congestion control: throttle sender when network overloaded does not provide: timing, minimum bandwidth guarantees UDP service: unreliable data transfer between sending and receiving process does not provide: connection setup, reliability, flow control, congestion control, timing, or bandwidth guarantee

14 Internet apps: application, transport protocols
layer protocol SMTP [RFC 2821] Telnet [RFC 854] HTTP [RFC 2616] FTP [RFC 959] proprietary (e.g. RealNetworks) (e.g., Dialpad) Underlying transport protocol TCP TCP or UDP typically UDP Application remote terminal access Web file transfer streaming multimedia and games Internet telephony

15 Programming application protocols
How do I program all of this? Layering allows programmers to write programs without understanding underlying functions of TCP/IP You will be evaluating this for yourselves... API to transport layer BSD socket API java.net API

16 Programming application protocols
How can applications programmatically access TCP/UDP/IP? Many possible interfaces Too many to teach adequately in detail Socket APIs BSD socket API Java socket API Other APIs Client-side Java URLconnections Server-side Java servlets RPC, CORBA, Java RMI (not covered)

17 Socket programming socket Socket API
a host-local, application-created/owned, OS-controlled interface (a “door”) into which application process can both send and receive messages to/from another (remote or local) application process socket Socket API introduced in BSD4.1 UNIX, 1981 client/server paradigm socket API supports three main usages unreliable datagram (UDP) reliable, byte stream (TCP) raw IP datagrams (IP)

18 Socket-programming using TCP
Socket: a door between application process and end-end- transport protocol (UCP or TCP) TCP service: reliable transfer of bytes from one process to another controlled by application developer controlled by application developer process TCP with buffers, variables socket process TCP with buffers, variables socket controlled by operating system controlled by operating system internet host or server host or server

19 Socket programming with TCP
Client must contact server server process must first be running server must have created a “listening” socket that welcomes client’s initial contact Client contacts server by: creating client-local TCP socket specifying server IP address and port number of server process When client creates socket: client TCP establishes connection to server TCP When contacted by client, server TCP creates new socket for server process to communicate with client allows server to talk with multiple clients (using multiple sockets) TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server application viewpoint

20 Sockets in action *,SIP:80 CIP:1099,SIP:80 *,SIP:80 CIP:1100,SIP:80

21 BSD sockets in C/Unix Socket API (socket.h)
socket(): create unnamed socket (data structure) UDP (SOCK_DGRAM), TCP (SOCK_STREAM) IP (SOCK_RAW) bind(): name socket (bind local address to socket) listen(): enable socket to accept connections accept(): get connect() request from listen queue, allocate file descriptor for new socket connect(): initiate connection on a socket (TCP handshake) send(), sendto(), sendmsg(), writev(), write(): send data recv(), recvfrom(), recvmsg(), readv(), read(): receive data setsockopt(), getsockopt(): set socket options (such as buffer sizes, flag fields) close(), shutdown(): teardown connection

22 BSD sockets in action UDP example TCP example client server client
bind() bind() socket() bind() connect() listen() sendto() accept() recvfrom() write() read() sendto() write() recvfrom() read()

23 BSD example For reference only...

24 Java network programming
Java network applications java.net package System-dependent implementations

25 Java installation on church/state
J2SE javac java compiler java java interpreter

26 java.net classes Low-level networking classes (Sockets and Packets)
High-level URL networking classes java.lang.Object java.net.Socket java.net.ServerSocket java.net.DatagramSocket java.net.MulticastSocket java.net.DatagramPacket java.net.URL java.net.URLConnection java.net.HttpURLConnection java.net.URLencoder java.net.InetAddress

27 java.net.Socket Constructors Some methods Socket(InetAddress, int)
Socket(String, int) Socket(InetAddress, int, InetAddress, int) Some methods getInputStream() getOutputStream getInetAddress() getPort() getLocalAddress() getLocalPort() get/set individual socket options

28 java.net.ServerSocket Constructors Some methods ServerSocket(int)
ServerSocket(int, int) // backlog specified ServerSocket(int, int, InetAddress) // local address and backlog specified Some methods accept() getInetAddress() getLocalPort()

29 Socket programming with TCP
Example client-server app: client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer stream) server reads line from socket server converts line to uppercase, sends back to client client reads, prints modified line from socket (inFromServer stream) Input stream: sequence of bytes into process Output stream: sequence of bytes out of process outToServer iinFromServer inFromUser client socket

30 Java client/server socket interaction: TCP
Server (running on hostid) Client create socket, port=x, for incoming request: welcomeSocket = ServerSocket() close connectionSocket read reply from clientSocket TCP connection setup create socket, connect to hostid, port=x clientSocket = Socket() wait for incoming connection request connectionSocket = welcomeSocket.accept() send request using clientSocket read request from connectionSocket write reply to

31 Example: Java client (TCP)
import java.io.*; import java.net.*; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket = new Socket("hostname", 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); Create input stream Create client socket, connect to server Create output stream attached to socket

32 Example: Java client (TCP), cont.
Create input stream attached to socket BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + '\n'); modifiedSentence = inFromServer.readLine(); System.out.println("FROM SERVER: " + modifiedSentence); clientSocket.close(); } Send line to server Read line from server

33 Example: Java server (TCP)
import java.io.*; import java.net.*; class TCPServer { public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); Create welcoming socket at port 6789 Wait, on welcoming socket for contact by client Create input stream, attached to socket

34 Example: Java server (TCP), cont
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + '\n'; outToClient.writeBytes(capitalizedSentence); } Create output stream, attached to socket Read in line from socket Write out line to socket End of while loop, loop back and wait for another client connection

35 Socket programming with UDP
UDP: no “connection” between client and server no handshaking sender explicitly attaches IP address and port of destination server must extract IP address, port of sender from received datagram UDP: transmitted data may be received out of order, or lost application viewpoint UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server

36 java.net.DatagramSocket
Constructors DatagramSocket() DatagramSocket(int) // bind to specific port DatagramSocket(int, InetAddress) // specify local address Some methods getLocalAddress() getLocalPort() receive(DatagramPacket) send(DatagramPacket) get/set individual socket options

37 java.net.DatagramPacket
Constructors DatagramPacket(byte[], int) // receiving packets DatagramPacket(byte[], int, InetAddress, int) // sending packets Some methods getAddress() // remote address getPort() // remote port getLength() // get packet length getData() // return data received or to be sent setAddress(InetAddress) // set remote address setData(byte[]) // set packet data setLength(int) // set packet length setPort(int) // set remote port

38 Client/server socket interaction: UDP
Server (running on hostid) create socket, clientSocket = DatagramSocket() Client Create, address (hostid, port=x, send datagram request using clientSocket create socket, port=x, for incoming request: serverSocket = DatagramSocket() read request from serverSocket close clientSocket read reply from clientSocket write reply to serverSocket specifying client host address, port umber

39 Example: Java client (UDP)
import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName("hostname"); byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024]; String sentence = inFromUser.readLine(); sendData = sentence.getBytes(); Create input stream Create client socket Translate hostname to IP address using DNS

40 Example: Java client (UDP), cont.
Create datagram with data-to-send, length, IP addr, port DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); } Send datagram to server Read datagram from server

41 Example: Java server (UDP)
import java.io.*; import java.net.*; class UDPServer { public static void main(String args[]) throws Exception { DatagramSocket serverSocket = new DatagramSocket(9876); byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; while(true) DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); Create datagram socket at port 9876 Create space for received datagram Receive datagram

42 Example: Java server (UDP), cont
String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serverSocket.send(sendPacket); } Get IP addr port #, of sender Create datagram to send to client Write out datagram to socket End of while loop, loop back and wait for another datagram

43 High-level Java networking classes
Socket/Packet Low level building blocks Must implement all application-level logic Many protocols based on URLs and/or tunneled in HTTP Program at a higher-level to hide underlying protocol details Do not re-implement HTTP, URL parsing, MIME handling for each application

44 High-level client-side Java networking classes
java.net.URL Represent a URL object java.net.URLConnection Represent a connection to a URL which can be read and written from java.net.HttpURLConnection Subclass of URLConnection for URLs Example

45 High-level server-side Java networking classes
Servlets Dynamically generate content Implement common protocol header logic Example http servlets Cookies Content-type Content-length Servlet classes javax.servlet.Servlet javax.servlet.HttpServlet init() service() destroy() javax.servlet.ServletRequest javax.servlet.ServletResponse javax.servlet.HttpServletRequest javax.servlet.HttpServletResponse


Download ppt "CSE524: Lecture 3 Application layer."

Similar presentations


Ads by Google