2: application layer
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
2: Application Layer 1
Chapter 2Application Layer
Computer Networking: A Top Down Approach, 5th edition. Jim Kurose, Keith RossAddison-Wesley, April 2009.
2: Application Layer 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 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 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 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 6
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
2: Application Layer 7
Client/server socket interaction: UDP
Server (running on hostid)
closeclose()
read datagram usingrecvfrom
create socket,
clifd = socket()
Client
Create datagram with server IP andport=x; send datagram via sendto
create socket,port= x.srvfd = socket()bind()
read datagram usingrecvfrom
write reply usingsendtospecifying client address,port number
2: Application Layer 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 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 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 11
Chapter 2: Summary
application architectures client-server P2P hybrid
application service requirements: reliability, bandwidth,
delay
Internet transport service model connection-oriented,
reliable: TCP unreliable, datagrams:
UDP
our study of network apps now complete! specific protocols:
HTTP FTP SMTP, POP, IMAP DNS P2P: BitTorrent, Skype
socket programming
2: Application Layer 12
Chapter 2: Summary
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
Most importantly: learned about protocols
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”