Chapter 2 Application layer r 2 1 Principles
- Slides: 26
Chapter 2: Application layer r 2. 1 Principles of r r network applications 2. 2 Web and HTTP Internet gaming 2. 3 FTP 2. 4 Electronic Mail v SMTP, POP 3, IMAP r 2. 5 DNS r 2. 6 P 2 P file sharing r VOIP r 2. 8 Socket programming with TCP r 2. 9 Socket programming with UDP r 2. 10 Building a Web server 2: Application Layer 1
Definition v v also called IP Telephony, Internet telephony, Broadband Phone and Voice over Broadband the routing of voice conversations over the Internet or through any other IP-based network Cisco IP Phone 7941 G 2: Application Layer 2
Big Picture r Modes of operation: v PC to PC v PC to phone v Phone to PC v Phone to Phone r Traffic go through Packet Switched Network instead of Public Switched Telephone Network (PSTN) From Wikipedia, the free encyclopedia 2: Application Layer 3
Challenges r Quality of Service (Qo. S) v Internet provides best of service v No guarantee for latency, jitter… r Need Internet connection v Home broadband is not reliable r Power issue v VOIP phone, Cable Modem/DSL, Computer 2: Application Layer 4
Challenges r Security v Most unencrypted v VOIP spam challenges r Integration into global telephone number system r Emergency call availability & functionality Power, Internet connection v Call routing, location service v 2: Application Layer 5
Qo. S r Deal with Jitter v Smoothed by playback buffer r Bandwidth v 64 kbps or less v Depends on codec and use of silence supression 2: Application Layer 6
Chapter 2: Application layer r 2. 1 Principles of r r network applications 2. 2 Web and HTTP Internet gaming 2. 3 FTP 2. 4 Electronic Mail v r 2. 6 P 2 P file sharing r VOIP r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP SMTP, POP 3, IMAP r 2. 5 DNS 2: Application Layer 7
Socket programming Goal: learn how to build client/server application that communicate using sockets Socket API r introduced in BSD 4. 1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of transport service via socket API: v v unreliable datagram (UDP) reliable, byte stream-oriented (TCP) 2: Application Layer 8
Socket-programming using TCP Socket: an interface between application process and end-transport protocol (UCP or TCP) Why socket? : A Layer seen by application, OS transparent controlled by application developer controlled by operating system process socket TCP with buffers, variables host or server internet socket TCP with buffers, variables host or server 2: Application Layer 9
Socket programming with TCP Client must contact server r server process must first be running r server must have created socket (door) that accepts client’s contact Client contacts server by: r creating client-local TCP socket r specifying IP address, port number of server process r When client creates socket: client TCP establishes connection to server TCP r When contacted by client, server TCP creates new socket for server process to communicate with client v allows server to talk with multiple clients v 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 2: Application Layer 10
Many Versions of Socket APIs r Unix socket (berkeley socket) r Winsock r Mac. TCP r …. r We introduce Unix socket API here v Can program under SUN OS, Linux, etc v A good tutorial on socket programming: • http: //beej. us/guide/bgnet/ 2: Application Layer 11
Socket Descriptor Data Structure Descriptor Table 0 1 2 3 4 Family: AF_INET Service: SOCK_STREAM Local IP: 111. 22. 3. 4 Remote IP: 123. 45. 6. 78 Local Port: 2249 Remote Port: 3726 2: Application Layer 12
TCP Client/Server Socket Overview TCP Server socket() TCP Client bind() socket() listen() bind() connect() send() connection establishment data request accept() recv() data reply send() recv() close() end-of-file notification recv() close() 2: Application Layer 13
What is a Socket? int sockfd; /* socket descriptor */ if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) } perror(“socket”); exit(1); } r socket returns an integer (socket descriptor) sockfd < 0 indicates that an error occurred v socket descriptors are similar to file descriptors v r AF_INET: associates a socket with the Internet protocol family r SOCK_STREAM: selects the TCP protocol r SOCK_DGRAM: selects the UDP protocol 2: Application Layer 14
Socket Structure (Client) AF_INET struct sockaddr_in { short int sin_family; // Address family unsigned short int sin_port; // Port number struct in_addr sin_addr; // Internet address unsigned char sin_zero[8]; // all zero }; // Internet address (Network Byte Order) // (a structure for historical reasons) struct in_addr { unsigned long s_addr; // that's a 32 -bit long, or 4 bytes }; … 100 101 102 103 1 A 2 D 3 C 4 B … IP: 1 A. 2 D. 3 C. 4 B Big-Endian (Network Byte Order) 2: Application Layer 15
Bind (Client) int sockfd; struct sockaddr_in local_addr; local_addr. sin_family = AF_INET; local_addr. sin_port = 0; // random assign a port local_addr. sin_addr. s_addr = INADDR_ANY; // use my IP address memset(&(my_addr. sin_zero), '