Chapter 2 Application Layer

Similar documents
Chapter 2 Application Layer

Communication in Distributed Systems: Sockets Programming. Operating Systems

Chapter 2 outline. 2.1 Principles of app layer protocols

Chapter 2: outline. 2.1 principles of network applications. 2.6 P2P applications 2.7 socket programming with UDP and TCP

Introduction to Sockets 9/25/14

Computer Networking Introduction

Lecture 05: Application Layer (Part 02) FTP, Peer-to-Peer, . Dr. Anis Koubaa

CPSC 441 UDP Socket Programming. Department of Computer Science University of Calgary

CSCD 330 Network Programming Spring 2018

CSCD 330 Network Programming Spring 2018

CSCD 330 Network Programming Winter 2019

CPSC 441 Tutorial - 11 UDP Socket Programming Department of Computer Science University of Calgary

CS 355. Computer Networking. Wei Lu, Ph.D., P.Eng.

Lecture 3. Java Socket Programming. TCP, UDP and URL

Layer 4 - Transport Layer. What do we need a Transport Layer for? Transport Protocols in the TCP/IP Reference Model. The Transport Layer TCP and UDP

Computer Networks. 2.Application Layer. László Böszörményi Computer Networks Application Layer - 1

Layer 4 - Transport Layer

Process Communication COMPUTER NETWORKING Part 2

Computer Networks Unit II Transport layer (2012 pattern)

Part 2: Application Layer

Chapter 2: Application Layer last updated 22/09/03

Client/Server Computing & Socket Programming

TCP and UDP Socket Programming in JAVA TCP Socket Programming 1. Write code for Client and save in GreetingClient.java

JAVA SOCKET PROGRAMMING

Chapter 2 Application Layer

Chapter 2 Application Layer

Chapter 2 Application Layer

Chapter 2 Application Layer

Chapter 2 Application Layer

Chapter 2 Application Layer

Computer Networks 1 (Mạng Máy Tính 1) Lectured by: Dr. Phạm Trần Vũ

Chapter 2 Application Layer. 2: Application Layer 1

Chapter 2 Application Layer

Chapter 2: Application layer. Chapter 2 Application Layer. Some network apps. Chapter 2: Application Layer. Chapter 2: Application layer

Chapter 2: Application layer. Chapter 2 Application Layer. Chapter 2: Application Layer. Some network apps

Chapter 2 Application Layer

A note on the use of these ppt slides:

Πρωτόκολλα Διαδικτύου (ΨΣ-326 DS151)

Chapter 2 Application Layer

Chapter 2 Application Layer

Chapter 2 Application Layer

Chapter 2: Application layer. Chapter 2 Application Layer. Chapter 2: Application Layer. Some network apps

COMP 211 Chapter 2 Application Layer

Chapter 2 APPLICATIONS

COMPUTER NETWORKS CHAP 2 : APPLICATION LAYER

Data Communications & Networks. Session 2 Main Theme Application Layer. Dr. Jean-Claude Franchitti

Data Communications & Networks. Session 2 Main Theme Application Layer. Dr. Jean-Claude Franchitti

COMP 3331/9331: Computer Networks and Applications

SE322 Software Design and Architecture

Computer Networks. Application Layer

Chapter 2 Application Layer

CSCI Computer Networks Spring 2017

Chapter 2: Application layer. Computer Networks. Application Layer. Chapter 2: Application Layer. Some network apps. Bu-Ali Sina University, Hamedan

CC451 Computer Networks

55:134/22C:178 Computer Communications Lecture Note Set 2 Summer 2004

Computer Communication Networks Socket Programming

FTP. Mail. File Transfer Protocol (FTP) FTP commands, responses. Electronic Mail. TDTS06: Computer Networks

Chapter 2 Application Layer. 2: Application Layer 1

We will cover in this order: 2.1, 2.7, 2.5, 2.4, 2.2

Unit 1 Java Networking

Chapter 2a SOCKET PROGRAMMING

Foundations of Telematics

Chapter 2 APPLICATIONS

Tommy Färnqvist, IDA, Linköping University

Tonight. Communication. Middleware Protocols. Remote Procedure Call (RPC) Several common communication mechanisms RPC RMI Sockets Next week: HTTP,

Telematics Chapter 8: Transport Layer

Chapter II: Application Layer

Application Layer. Application Layer 1. By Mikkel Christiansen for NA mm7 Spring 2004

Chapter 3 Transport Layer

Chapter 3 Transport Layer

Chapter 3 Transport Layer

Chapter 2: outline. 2.6 P2P applications 2.7 socket programming with UDP and TCP

Chapter 2: Application layer

Telematics 1. Chapter 9 Internet Application Layer. Principles of network applications Important application protocols Socket programming

Computer Networks and Applications. Application Layer ( , DNS, P2P, Socket Programming)

Java Network Programming

Chapter 3: Transport Layer. Chapter 3 Transport Layer. Chapter 3 outline. Transport services and protocols

Application Programming Interfaces

CSC 401 Data and Computer Communications Networks

SOURCE CODE. //Socket Programming using TCP Sockets. Server.java

Client/Server Computing & Socket Programming

Chapter 2 Application Layer

Computer Networks. 5th of February, This exam consists of 6 questions with subquestions. Every subquestion counts for 10 points.

Chapter 1 Introduction

Chapter 2 Application Layer

Some network apps. Chapter 2 Application Layer. Chapter 2: Application layer. Chapter 2: Application Layer. Chapter 2: Application layer

Chapter 3 Transport Layer

Section 2: Application layer

Chapter 2 Application Layer

CPSC 441 Assignment-3 Discussion. Department of Computer Science University of Calgary

Chapter 2: Application layer

UDP Sockets TCP guarantees the delivery of packets and preserves their order on destination. Sometimes these features are not required, since they do

ECE 4450:427/527 - Computer Networks Spring 2017

CSC 4900 Computer Networks: P2P and Sockets

Outlines. Networking in Java. Internet hardware structure. Networking Diagram. IP Address. Networking in Java. Networking basics

Transport Layer. Chapter 3: Transport Layer

Chapter 6 Transport Layer

Chapter 8 Network Security

Chapter 4. Computer Networking: A Top Down Approach 5 th edition. Jim Kurose, Keith Ross Addison-Wesley, sl April 2009.

Chapter 3 Transport Layer

Transcription:

Chapter 2 Application Layer A note on the use of these ppt slides: We re making these slides freely available to all (faculty, students, readers). They re in PowerPoint form so you can add, modify, and delete slides (including this one) and slide content to suit your needs. They obviously represent a lot of work on our part. In return for use, we only ask the following: If you use these slides (e.g., in a class) in substantially unaltered form, that you mention their source (after all, we d like people to use our book!) If you post any slides in substantially unaltered form on a www site, that you note that they are adapted from (or perhaps identical to) our slides, and note our copyright of this material. Computer Networking: A Top Down Approach, 5 th edition. Jim Kurose, Keith Ross Addison-Wesley, April 2009. Thanks and enjoy! JFK/KWR All material copyright 1996-2010 J.F Kurose and K.W. Ross, All Rights Reserved Application 2-1

Chapter 2: Application layer 2.1 Principles of network applications 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS 2.6 P2P applications 2.7 Socket programming with TCP 2.8 Socket programming with UDP Application 2-2

Socket programming Goal: learn how to build client/server application that communicate using sockets Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm two types of transport service via socket API: unreliable datagram reliable, byte streamoriented socket a host-local, application-created, OS-controlled interface (a door ) into which application process can both send and receive messages to/from another application process Application 2-3

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

Socket programming with TCP Client must contact server server process must first be running server must have created socket (door) that welcomes client s contact Client contacts server by: creating client-local TCP socket specifying IP address, 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 source port numbers used to distinguish clients (more in Chap 3) application viewpoint TCP provides reliable, in-order transfer of bytes ( pipe ) between client and server Application 2-5

Client/server socket interaction: TCP Server (running on hostid) Client create socket, port=x, for incoming request: welcomesocket = ServerSocket() wait for incoming connection request connectionsocket = welcomesocket.accept() read request from connectionsocket write reply to connectionsocket close connectionsocket TCP connection setup create socket, connect to hostid, port=x clientsocket = Socket() send request using clientsocket read reply from clientsocket close clientsocket Application 2-6

Stream jargon keyboard monitor stream is a sequence of characters that flow into or out of a process. input stream is attached to some input source for the process, e.g., keyboard or socket. output stream is attached to an output source, e.g., monitor or socket. Client Process process input stream output stream infromuser outtoserver infromserver client TCP clientsocket socket input stream TCP socket to network from network Application 2-7

Socket programming with TCP Example client-server app: 1) client reads line from standard input (infromuser stream), sends to server via socket (outtoserver stream) 2) server reads line from socket 3) server converts line to uppercase, sends back to client 4) client reads, prints modified line from socket (infromserver stream) Application 2-8

Example: Java client (TCP) import java.io.*; import java.net.*; class TCPClient { This package defines Socket() and ServerSocket() classes create input stream create clientsocket object of type Socket, connect to server create output stream attached to socket public static void main(string argv[]) throws Exception { String sentence; server name, e.g., www.umass.edu String modifiedsentence; server port # BufferedReader infromuser = new BufferedReader(new InputStreamReader(System.in)); Socket clientsocket = new Socket("hostname", 6789); DataOutputStream outtoserver = new DataOutputStream(clientSocket.getOutputStream()); Application 2-9

Example: Java client (TCP), cont. create input stream attached to socket send line to server read line from server BufferedReader infromserver = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = infromuser.readline(); outtoserver.writebytes(sentence + '\n'); modifiedsentence = infromserver.readline(); System.out.println("FROM SERVER: " + modifiedsentence); close socket (clean up behind yourself!) clientsocket.close(); } } Application 2-10

Example: Java server (TCP) import java.io.*; import java.net.*; class TCPServer { create welcoming socket at port 6789 wait, on welcoming socket accept() method for client contact create, new socket on return create input stream, attached to socket 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())); Application 2-11

Example: Java server (TCP), cont create output stream, attached to socket read in line from socket DataOutputStream outtoclient = new DataOutputStream(connectionSocket.getOutputStream()); clientsentence = infromclient.readline(); write out line to socket } } } capitalizedsentence = clientsentence.touppercase() + '\n'; outtoclient.writebytes(capitalizedsentence); end of while loop, loop back and wait for another client connection Application 2-12

Chapter 2: Application layer 2.1 Principles of network applications 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS 2.6 P2P applications 2.7 Socket programming with TCP 2.8 Socket programming with UDP Application 2-13

Socket programming with UDP UDP: no connection between client and server no handshaking sender explicitly attaches IP address and port of destination to each packet server must extract IP address, port of sender from received packet 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 Application 2-14

Client/server socket interaction: UDP Server (running on hostid) Client create socket, port= x. serversocket = DatagramSocket() read datagram from serversocket create socket, clientsocket = DatagramSocket() Create datagram with server IP and port=x; send datagram via clientsocket write reply to serversocket specifying client address, port number read datagram from clientsocket close clientsocket Application 2-15

Example: Java client (UDP) keyboard monitor Output: sends packet (recall Process Client process that TCP sent byte stream ) input stream UDP packet infromuser sendpacket receivepacket client clientsocket UDP socket UDP packet UDP socket Input: receives packet (recall thattcp received byte stream ) to network from network Application 2-16

Example: Java client (UDP) import java.io.*; import java.net.*; create input stream create client socket translate hostname to IP address using DNS 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(); Application 2-17

Example: Java client (UDP), cont. create datagram with data-to-send, length, IP addr, port send datagram to server read datagram from server } 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(); } Application 2-18

Example: Java server (UDP) import java.io.*; import java.net.*; create datagram socket at port 9876 create space for received datagram receive datagram 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); Application 2-19

Example: Java server (UDP), cont get IP addr port #, of sender String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivepacket.getaddress(); int port = receivepacket.getport(); create datagram to send to client write out datagram to socket } } String capitalizedsentence = sentence.touppercase(); senddata = capitalizedsentence.getbytes(); DatagramPacket sendpacket = new DatagramPacket(sendData, senddata.length, IPAddress, port); serversocket.send(sendpacket); } end of while loop, loop back and wait for another datagram Application 2-20

Chapter 2: Summary our study of network apps now complete! application architectures client-server P2P hybrid application service requirements: reliability, bandwidth, delay Internet transport service model connection-oriented, reliable: TCP unreliable, datagrams: UDP specific protocols: HTTP FTP SMTP, POP, IMAP DNS P2P: BitTorrent, Skype socket programming Application 2-21

Chapter 2: Summary most importantly: learned about protocols typical request/reply message exchange: client requests info or service server responds with data, status code message formats: headers: fields giving info about data data: info being communicated Important themes: control vs. data msgs in-band, out-of-band centralized vs. decentralized stateless vs. stateful reliable vs. unreliable msg transfer complexity at network edge Application 2-22