1 / 12

2: Application Layer

Chapter 2 Application Layer. Computer Networking: A Top Down Approach , 5 th edition. Jim Kurose, Keith Ross Addison-Wesley, April 2009. 2: Application Layer. 1. Chapter 2: Application layer. 2.1 Principles of network applications 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail

Télécharger la présentation

2: Application Layer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 2Application Layer Computer Networking: A Top Down Approach, 5th edition. Jim Kurose, Keith RossAddison-Wesley, April 2009. 2: Application Layer 1

  2. 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 2: Application Layer 2

  3. recv and send • recv may be used instead of read (and is recommended): n = recv(fd, buffer, count, flags); • The first three arguments are the same as for read. The flags argument provides additional flexibility. Interesting flags are MSG_DONTWAIT and MSG_PEEK. Refer to recv(2) for details. 2: Application Layer 3

  4. recv and send • Similarly send may be used instead of write (and is also recommended): n = send(fd, buffer, count, flags); • Interesting flags are MSG_DONTWAIT, MSG_MORE and MSG_DONTROUTE. Refer to send(2) for details. 2: Application Layer 4

  5. 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 2: Application Layer 5

  6. application viewpoint UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server 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 2: Application Layer 6

  7. Client create socket, clifd = socket() Create datagram with server IP and port=x; send datagram viasendto read datagram using recvfrom write reply using sendto specifying client address, port number read datagram using recvfrom close close() Client/server socket interaction: UDP Server (running on hostid) create socket, port= x. srvfd = socket() bind() 2: Application Layer 7

  8. UDP Programming • The client functions for passing UDP datagrams are: socket(), sendto(), and recvfrom(). It is not necessary for the client to connect() with the server. (Although connect() can be used.) • The server uses socket(), bind(), recvfrom(), and sendto(). The server does not accept()a connection from the client, instead recvfrom() returns the data and client address. 2: Application Layer 8

  9. UDP Programming • The sendto() routine takes a destination address structure as an argument: typedef struct sockaddr SA; struct sockaddr_in srvaddr_in; memset(&srvaddr_in, 0, sizeof(srvaddr_in)); srvaddr.sin_family = AF_INET; srvaddr.sin_port = htons(9000); inet_pton(AF_INET, “10.10.0.9”, &srvaddr_in.sin_addr.s_addr); sfd = socket(AF_INET, SOCK_DGRAM, 0); sendto(sfd, msg, msglen, 0, (SA *)&srvaddr_in, sizeof(srvaddr_in)); 2: Application Layer 9

  10. UDP Programming • recvfrom() returns an address as an argument. The address is used by the server to respond to the proper client: n = recvfrom(sockfd, mesg, mesg_len, 0, (SA *)&cliaddr_in, &len); sendto(sockfd, mesg, n, 0, (SA *)&cliaddr_in, len); • A NULL address may be used in recvfrom() if we do not care about the address. • Refer to udp_server.cpp for a complete example of UDP socket programming (a modified echo server). • In-class Exercise: Write a udp_client.cpp program to communicate with udp_server.cpp. It should prompt the user for input, send the input to the server, and then read and display the response. 2: Application Layer 10

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

  12. 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” 2: Application Layer 12

More Related