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

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

Computer Networking Introduction

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

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

CSCD 330 Network Programming Spring 2018

CSCD 330 Network Programming Spring 2018

CSCD 330 Network Programming Winter 2019

Client/Server Computing & Socket Programming

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

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

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

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

Layer 4 - Transport Layer

JAVA SOCKET PROGRAMMING

Process Communication COMPUTER NETWORKING Part 2

Computer Networks Unit II Transport layer (2012 pattern)

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

Part 2: Application Layer

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

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

Foundations of Telematics

Chapter 2 Application Layer

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

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

Chapter 2 Application Layer

Chapter 2 Application Layer

Java Network Programming

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

A note on the use of these ppt slides:

Chapter 2 Application Layer. 2: Application Layer 1

CC451 Computer Networks

Chapter 2 Application Layer

Chapter 2a SOCKET PROGRAMMING

Chapter 2 Application Layer

Computer Communication Networks Socket Programming

Chapter 2 Application Layer

COMP 211 Chapter 2 Application Layer

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

Chapter 2 APPLICATIONS

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

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

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

COMPUTER NETWORKS CHAP 2 : APPLICATION LAYER

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

Chapter 3 Transport Layer

COMP 3331/9331: Computer Networks and Applications

Chapter 3 Transport Layer

SE322 Software Design and Architecture

Unit 1 Java Networking

Chapter 2 Application Layer

CSCI Computer Networks Spring 2017

Chapter 2 APPLICATIONS

Chapter 3 Transport Layer

Computer Networks. Application Layer

Chapter II: Application Layer

Chapter 2 Application Layer. 2: Application Layer 1

Chapter 2 Application Layer

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

Tommy Färnqvist, IDA, Linköping University

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

Client/Server Computing & Socket Programming

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

CSC 401 Data and Computer Communications Networks

Telematics Chapter 8: Transport Layer

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

ECE 4450:427/527 - Computer Networks Spring 2017

Chapter 1 Introduction

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

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

Chapter 2 Application Layer

Chapter 8 Network Security

Chapter 2: Application layer

Application Programming Interfaces

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

Chapter 3 Transport Layer

Chapter 2: Application layer

CC451 Computer Networks

Review of Previous Lecture

Different Layers Lecture 21

Chapter 2 Application Layer

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

Advanced Java Programming. Networking

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

Web Protocols and Practice

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

Chapter 2 Application Layer. Lecture 4: principles of network applications. Computer Networking: A Top Down Approach

Chapter 7: Multimedia Networking

Transport Layer. Chapter 3: Transport Layer

Transcription:

Internet and Intranet Protocols and Applications Lecture 4: Application Layer 3: Socket Programming Spring 2006 Arthur Goldberg Computer Science Department New York University artg@cs.nyu.edu 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. Thanks and enjoy! JFK/KWR All material copyright 1996-2004 J.F Kurose and K.W. Ross, All Rights Reserved Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley, July 2004. 2 Chapter 2: Application layer Socket programming 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 file sharing 2.7 Socket programming with TCP 2.8 Socket programming with UDP 2.9 Building a Web Goal: learn how to build client/ application that communicate using s Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/ paradigm two types of transport service via API: unreliable datagram reliable, byte oriented a host-local, application-created, OS-controlled interface through which an application can both send and receive messages to/from another application 2: Application Layer 3 2: Application Layer 4

Socket-programming using TCP Socket programming with TCP Socket: a door between application and endend-transport protocol (UCP or TCP) TCP service: reliable transfer of bytes from one to another application developer operating system TCP with buffers, variables host or internet TCP with buffers, variables host or application developer operating system 2: Application Layer 5 must contact must first be running must have created (door) that welcomes client s contact contacts by: creating client-local TCP specifying IP address, port number of s when client creates : client TCP establishes connection to TCP When contacted by client, TCP creates new for to communicate with client s allows 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 2: Application Layer 6 Stream jargon Java TCP Socket Programming A is a sequence of characters that flow into or out of a. An input is attached to some input source for the, e.g., keyboard or. An output is attached to an output source, e.g., monitor or. Example client- app: 1) client reads line from standard input (infromuser ), sends to via (outtoserver ) 2) reads line from 3) converts line to uppercase, sends back to client 4) client reads, prints modified line from (infromserver ) Process input output keyboard monitor infromuser outtoserver infromserver client TCP input TCP to network from network 2: Application Layer 7 2: Application Layer 8

/ interaction: TCP Example: Java client (TCP) Server (running on hostid) create, port=x, for incoming request: welcomesocket = ServerSocket() TCP wait for incoming connection request connection setup connectionsocket = welcomesocket.accept() read request from connectionsocket write reply to connectionsocket close connectionsocket create, connect to hostid, port=x = Socket() send request using read reply from close 2: Application Layer 9 input client, connect to output attached to class TCP public static void main(string argv[]) throws Exception String sentence; String modifiedsentence; BufferedReader infromuser = new BufferedReader(new InputStreamReader(System.in)); Socket = new Socket("hostname", 6789); DataOutputStream outtoserver = new DataOutputStream(.getOutputStream()); 2: Application Layer 10 Example: Java client (TCP), cont. Example: Java (TCP) input attached to Send line to Read line from BufferedReader infromserver = new BufferedReader(new InputStreamReader(.getInputStream())); sentence = infromuser.readline(); outtoserver.writebytes(sentence + '\n'); modifiedsentence = infromserver.readline(); System.out.println("FROM SERVER: " + modifiedsentence);.close(); welcoming at port 6789 Wait for connect from client on welcoming input, attached to 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 infrom = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); 2: Application Layer 11 2: Application Layer 12

Example: Java (TCP), cont Chapter 2: Application layer output, attached to Read in line from Write out line to DataOutputStream outto = new DataOutputStream(connectionSocket.getOutputStream()); clientsentence = infrom.readline(); capitalizedsentence = clientsentence.touppercase() + '\n'; outto.writebytes(capitalizedsentence); End of while loop, loop back and wait for another client connection 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 file sharing 2.7 Socket programming with TCP 2.8 Socket programming with UDP 2.9 Building a Web 2: Application Layer 13 2: Application Layer 14 Socket programming with UDP / interaction: UDP UDP: no connection between client and no handshaking sender explicitly attaches IP address and port of destination to each packet 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 (running on hostid) create, port=x, for incoming request: Socket = DatagramSocket() read request from Socket write reply to Socket specifying client host address, port number create, = DatagramSocket(), address (hostid, port=x, send datagram request using read reply from close 2: Application Layer 15 2: Application Layer 16

Example: Java client (UDP) Example: Java client (UDP) keyboard monitor Process Output: sends packet (TCP sent byte ) input UDP packet infromuser sendpacket to network receivepacket client UDP UDP packet from network UDP Input: receives packet (TCP received byte ) 2: Application Layer 17 input client Translate hostname to IP address using DNS class UDP public static void main(string args[]) throws Exception BufferedReader infromuser = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName("hostname"); byte[] senddata = new byte[1024]; byte[] receivedata = new byte[1024]; String sentence = infromuser.readline(); senddata = sentence.getbytes(); 2: Application Layer 18 Example: Java client (UDP), cont. Example: Java (UDP) datagram with data-to-send, length, IP addr, port Send datagram to Read datagram from DatagramPacket sendpacket = new DatagramPacket(sendData, senddata.length, IPAddress, 9876);.send(sendPacket); DatagramPacket receivepacket = new DatagramPacket(receiveData, receivedata.length);.receive(receivepacket); String modifiedsentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedsentence);.close(); 2: Application Layer 19 datagram at port 9876 space for received datagram Receive datagram class UDPServer public static void main(string args[]) throws Exception DatagramSocket Socket = new DatagramSocket(9876); byte[] receivedata = new byte[1024]; byte[] senddata = new byte[1024]; while(true) DatagramPacket receivepacket = new DatagramPacket(receiveData, receivedata.length); Socket.receive(receivePacket); 2: Application Layer 20

Example: Java (UDP), cont Chapter 2: Application layer Get IP addr port #, of sender datagram to send to client Write out datagram to 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); Socket.send(sendPacket); End of while loop, loop back and wait for another datagram 2: Application Layer 21 2.1 Principles of network applications app architectures app requirements 2.2 Web and HTTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS 2.6 P2P file sharing 2.7 Socket programming with TCP 2.8 Socket programming with UDP 2.9 Building a Web 2: Application Layer 22 Building a simple Web Chapter 2: Summary handles one HTTP request accepts the request parses header obtains requested file from s file system creates HTTP response message: header lines + file sends response to client after creating, you can request file using a browser (eg IE explorer) see text for details 2: Application Layer 23 Application architectures client- 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 programming 2: Application Layer 24

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