Application Layer and Socket Programming

elliando dias
elliando diassoftware developer à -
15-441: Computer Networking Lecture 3: Application Layer and Socket Programming
Lecture Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Applications and Application-Layer Protocols ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],application transport network data link physical application transport network data link physical application transport network data link physical
Client-Server Paradigm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],application transport network data link physical application transport network data link physical request reply
Ftp: The File Transfer Protocol ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],file transfer remote file system user  at host FTP server FTP user interface FTP client local file system
Ftp: Separate Control, Data Connections ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],FTP client FTP server TCP control connection port 21 TCP data connection port 20
Ftp Commands, Responses ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What Transport Service Does an Application Need? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Transport Service Requirements of Common Apps no loss no loss no loss loss-tolerant loss-tolerant loss-tolerant no loss elastic elastic elastic audio: 5Kb-1Mb video:10Kb-5Mb same as above  few Kbps elastic no no no yes, 100’s msec yes, few secs yes, 100’s msec yes and no file transfer e-mail web documents real-time audio/ video stored audio/video interactive games financial apps Application Data loss Bandwidth Time Sensitive
Lecture Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Server and Client TCP/UDP IP Ethernet Adapter Server TCP/UDP IP Ethernet Adapter Clients Server and Client exchange messages over the network through a common  Socket API Socket API hardware kernel  space user  space ports
User Datagram Protocol(UDP):  An Analogy ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Example UDP applications Multimedia, voice over IP ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Transmission Control Protocol (TCP): An Analogy  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Network Addressing Analogy 412-268-8000 ext.123 Central Number Applications/Servers Web Port 80 Mail Port 25 Exchange Area Code 412-268-8000 ext.654 IP Address Network No. Host Number Telephone No 15-441 Students Clients Professors at CMU Network Programming Telephone Call Port No. Extension
Concept of Port Numbers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],TCP/UDP IP Ethernet Adapter NTP daemon Web  server port 123 port 80
Names and Addresses ,[object Object],[object Object],[object Object],[object Object],[object Object]
Internet Addressing Data Structure ,[object Object],#include < netinet/in.h > /* Internet address structure */ struct in_addr  { u_long  s_addr ; /* 32-bit IPv4 address */ }; /* network byte ordered */ /* Socket address, Internet style. */ struct sockaddr_in  { u_char  sin_family ; /* Address Family */ u_short  sin_port ; /* UDP or TCP Port# */ /* network byte ordered */ struct in_addr  sin_addr ;  /* Internet Address */ char  sin_zero[8]; /* unused */ };
Byte Ordering ,[object Object],[object Object],[object Object],[object Object],[object Object],128 2 194 95 union { u_int32_t addr;  /* 4 bytes address */ char c[4]; } un; /* 128.2.194.95 */ un.addr = 0x8002c25f; /* c[0] = ? */ c[0] c[1] c[2] c[3] 95 194 2 128
Byte Ordering Functions ,[object Object],[object Object],[object Object],[object Object],[object Object],#include <netinet/in.h> unsigned long int  htonl (unsigned long int hostlong); unsigned short int  htons (unsigned short int hostshort); unsigned long int  ntohl (unsigned long int netlong); unsigned short int  ntohs (unsigned short int netshort);
Lecture Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],What is a Socket? int fd;  /* socket descriptor */ if ((fd =  socket ( AF_INET ,  SOCK_STREAM , 0)) < 0) } perror(“socket”); exit(1); }
[object Object],[object Object],TCP IP Ethernet Adapter Web Server Port 80 TCP Server
[object Object],int fd; /* socket descriptor */ if((fd =  socket ( AF_INET ,  SOCK_STREAM , 0)) < 0) { perror(“socket”); exit(1); } ,[object Object],[object Object],[object Object],[object Object],Socket I/O: socket()
[object Object],int fd; /* socket descriptor */ struct sockaddr_in  srv; /* used by bind() */ /* create the socket */ srv.sin_family =  AF_INET ; /* use the Internet addr family */ srv.sin_port =  htons ( 80 ); /* bind socket ‘fd’ to port 80*/ /* bind: a client may connect to any of my addresses */ srv.sin_addr.s_addr =  htonl ( INADDR_ANY ); if( bind (fd, (struct sockaddr*) &srv, sizeof(srv)) < 0) { perror(&quot;bind&quot;); exit(1); } ,[object Object],Socket I/O: bind()
Socket I/O: listen() ,[object Object],int fd;   /* socket descriptor */ struct sockaddr_in srv;   /* used by bind() */ /* 1) create the socket */ /* 2) bind the socket to a port */ if( listen (fd, 5) < 0) { perror(“listen”); exit(1); } ,[object Object]
Socket I/O: accept() ,[object Object],int fd; /* socket descriptor */ struct sockaddr_in srv;   /* used by bind() */ struct sockaddr_in cli;   /* used by accept() */ int newfd;   /* returned by accept() */ int cli_len = sizeof(cli); /* used by accept() */ /* 1) create the socket */ /* 2) bind the socket to a port */ /* 3) listen on the socket */ newfd =  accept (fd, (struct sockaddr*) &cli, &cli_len); if(newfd < 0) { perror(&quot;accept&quot;); exit(1); } ,[object Object],[object Object]
Socket I/O: accept() continued... struct sockaddr_in cli; /* used by accept() */ int newfd; /* returned by accept() */ int cli_len = sizeof(cli); /* used by accept() */ newfd =  accept (fd, (struct sockaddr*) &cli, &cli_len); if(newfd < 0) { perror(&quot;accept&quot;); exit(1); } ,[object Object],[object Object],[object Object],[object Object],[object Object]
Socket I/O: read() ,[object Object],[object Object],int fd; /* socket descriptor */ char buf[512]; /* used by read() */ int nbytes;   /* used by read() */ /* 1) create the socket */ /* 2) bind the socket to a port */ /* 3) listen on the socket */ /* 4) accept the incoming connection */ if((nbytes =  read (newfd, buf, sizeof(buf))) < 0) { perror(“read”); exit(1); }
TCP Client ,[object Object],[object Object],TCP IP Ethernet Adapter 2 Web Clients
Dealing with IP Addresses ,[object Object],struct sockaddr_in srv; srv.sin_addr.s_addr =  inet_addr(“128.2.35.50”); if(srv.sin_addr.s_addr == (in_addr_t) -1) { fprintf(stderr, &quot;inet_addr failed!&quot;); exit(1); } Converting a numerical address to a string: struct sockaddr_in srv; char *t =  inet_ntoa(srv.sin_addr); if(t == 0) { fprintf(stderr, “inet_ntoa failed!”); exit(1); } Converting strings to numerical address:
Translating Names to Addresses ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],#include <netdb.h> struct hostent *hp; /*ptr to host info for remote*/  struct sockaddr_in peeraddr; char *name = “www.cs.cmu.edu”; peeraddr.sin_family = AF_INET;  hp = gethostbyname(name)  peeraddr.sin_addr.s_addr = ((struct in_addr*)(hp->h_addr))->s_addr;
Socket I/O: connect() ,[object Object],int fd; /* socket descriptor */ struct sockaddr_in srv; /* used by connect() */ /* create the socket */ /* connect: use the Internet address family */ srv.sin_family =  AF_INET ; /* connect: socket ‘fd’ to port 80 */ srv.sin_port = htons( 80 ); /* connect: connect to IP Address “128.2.35.50” */ srv.sin_addr.s_addr =  inet_addr (“ 128.2.35.50 ”); if( connect (fd, (struct sockaddr*) &srv, sizeof(srv)) < 0) { perror(”connect&quot;); exit(1); }
Socket I/O: write() ,[object Object],int fd; /* socket descriptor */ struct sockaddr_in srv; /* used by connect() */ char buf[512]; /* used by write() */ int nbytes; /* used by write() */ /* 1) create the socket */ /* 2) connect() to the server */ /* Example: A client could “write” a request to a server */ if((nbytes =  write (fd, buf, sizeof(buf))) < 0) { perror(“write”); exit(1); }
Review: TCP Client-Server Interaction socket() bind() listen() accept() write() read() read() TCP Server close() socket() TCP Client connect() write() read() close() connection establishment data request data reply end-of-file notification from UNIX Network Programming Volume 1, figure 4.1
UDP Server Example ,[object Object],[object Object],UDP IP Ethernet Adapter NTP daemon Port 123
Socket I/O: socket() ,[object Object],int fd; /* socket descriptor */ if((fd =  socket (AF_INET,  SOCK_DGRAM , 0)) < 0) { perror(“socket”); exit(1); } ,[object Object],[object Object],[object Object],[object Object]
Socket I/O: bind() ,[object Object],int fd; /* socket descriptor */ struct sockaddr_in srv; /* used by bind() */ /* create the socket */ /* bind: use the Internet address family */ srv.sin_family =  AF_INET ; /* bind: socket ‘fd’ to port 80*/ srv.sin_port = htons( 80 ); /* bind: a client may connect to any of my addresses */ srv.sin_addr.s_addr = htonl( INADDR_ANY ); if( bind (fd, (struct sockaddr*) &srv, sizeof(srv)) < 0) { perror(&quot;bind&quot;); exit(1); } ,[object Object]
Socket I/O: recvfrom() ,[object Object],int fd; /* socket descriptor */ struct sockaddr_in srv; /* used by bind() */ struct sockaddr_in cli; /* used by recvfrom() */ char buf[512]; /* used by recvfrom() */ int cli_len = sizeof(cli);  /* used by recvfrom() */ int nbytes; /* used by recvfrom() */ /* 1) create the socket */ /* 2) bind to the socket */ nbytes =  recvfrom (fd, buf, sizeof(buf), 0 /* flags */,   (struct sockaddr*) &cli, &cli_len); if(nbytes < 0) { perror(“recvfrom”); exit(1); }
Socket I/O: recvfrom() continued... nbytes =  recvfrom (fd, buf, sizeof(buf), 0 /* flags */,   (struct sockaddr*) cli, &cli_len); ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
UDP Client Example ,[object Object],TCP IP Ethernet Adapter 2 UDP Clients ports
Socket I/O: sendto() ,[object Object],[object Object],[object Object],int fd; /* socket descriptor */ struct sockaddr_in srv; /* used by sendto() */ /* 1) create the socket */ /* sendto: send data to IP Address “128.2.35.50” port 80 */ srv.sin_family =  AF_INET ; srv.sin_port = htons( 80 );  srv.sin_addr.s_addr = inet_addr(“ 128.2.35.50 ”); nbytes =  sendto (fd, buf, sizeof(buf), 0 /* flags */,   (struct sockaddr*) &srv, sizeof(srv)); if(nbytes < 0) { perror(“sendto”); exit(1); }
Review: UDP Client-Server Interaction socket() bind() recvfrom() sendto() UDP Server socket() UDP Client sendto() recvfrom() close() blocks until datagram received from a client data request data reply from UNIX Network Programming Volume 1, figure 8.1
The UDP Server ,[object Object],UDP IP Ethernet Adapter UDP Server Port 2000 Port 3000
UDP Server: Servicing Two Ports  ,[object Object],int s1; /* socket descriptor 1 */ int s2; /* socket descriptor 2 */ /* 1) create socket s1 */ /* 2) create socket s2 */ /* 3) bind s1 to port 2000 */ /* 4) bind s2 to port 3000 */ while(1) { recvfrom (s1, buf, sizeof(buf), ...); /* process buf */ recvfrom (s2, buf, sizeof(buf), ...); /* process buf */ }
Socket I/O: select() ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],int select(int  maxfds , fd_set * readfds , fd_set * writefds ,    fd_set * exceptfds , struct timeval *timeout); FD_CLR(int fd, fd_set *fds);  /* clear the bit for  fd  in  fds  */ FD_ISSET(int fd, fd_set *fds); /* is the bit for  fd  in  fds ? */ FD_SET(int fd, fd_set *fds);  /* turn on the bit for  fd  in fds */ FD_ZERO(fd_set *fds);  /* clear all bits in  fds  */
Socket I/O: select() ,[object Object],[object Object],[object Object],[object Object],[object Object],int select(int maxfds, fd_set *readfds, fd_set *writefds,    fd_set *exceptfds, struct timeval * timeout ); struct timeval { long tv_sec; /* seconds / long tv_usec; /* microseconds */ }
Socket I/O: select() int s1, s2;  /* socket descriptors */ fd_set readfds; /* used by select() */ /* create and bind s1 and s2 */ while(1) { FD_ZERO (&readfds); /* initialize the fd set */ FD_SET (s1, &readfds); /* add s1 to the fd set */ FD_SET(s2, &readfds); /* add s2 to the fd set */ if( select (s2+1, &readfds, 0, 0, 0) < 0) { perror(“select”); exit(1); } if( FD_ISSET (s1, &readfds)) { recvfrom (s1, buf, sizeof(buf), ...); /* process buf */ } /* do the same for s2 */ } ,[object Object]
TCP IP Ethernet Adapter Web Server Port 80 How can a a  web server  manage multiple connections simultaneously? Port 8001 More Details About a Web Server
Socket I/O: select() ,[object Object],int fd, next=0; /* original socket */ int newfd[10];  /* new socket descriptors */ while(1) { fd_set readfds; FD_ZERO (&readfds);  FD_SET (fd, &readfds); /* Now use FD_SET to initialize other newfd’s   that have already been returned by accept() */ select ( maxfd +1, &readfds, 0, 0, 0); if( FD_ISSET (fd, &readfds)) { newfd[ next++ ] =  accept (fd, ...);  } /* do the following for each descriptor newfd[ n ]   */ if( FD_ISSET (newfd[ n ], &readfds)) { read (newfd[ n ], buf, sizeof(buf)); /* process data */ } }
A Few Programming Notes: Representing Packets 0  1  2  3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |  Type  | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |  Length  |  Checksum  | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |  Address  |  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Type: 4-byte integer Length: 2-byte integer Checksum: 2-byte integer Address: 4-byte IP address
A Few Programming Notes: Building a Packet in a Buffer struct packet { u_int32_t type; u_int16_t length; u_int16_t checksum; u_int32_t address; }; /* ================================================== */ char buf[1024]; struct packet *pkt; pkt = (struct packet*) buf; pkt->type =  htonl (1); pkt->length =  htons (2); pkt->checksum =  htons (3); pkt->address =  htonl (4);
Socket Programming References ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
1 sur 52

Recommandé

Arp (address resolution protocol)Arp (address resolution protocol)
Arp (address resolution protocol)tigerbt
7.4K vues15 diapositives
Socket ProgrammingSocket Programming
Socket Programmingelliando dias
2K vues20 diapositives
Dhcp pptDhcp ppt
Dhcp pptHema Dhariwal
73.9K vues23 diapositives

Contenu connexe

Tendances

Eigrp.pptEigrp.ppt
Eigrp.pptEdgardo Scrimaglia
13.3K vues65 diapositives
MikroTik & RouterOSMikroTik & RouterOS
MikroTik & RouterOSFaelix Ltd
1.5K vues50 diapositives
DHCPDHCP
DHCPselvakumar_b1985
526 vues10 diapositives
OSPF BasicsOSPF Basics
OSPF BasicsMartin Bratina
9K vues36 diapositives

Tendances(20)

Eigrp.pptEigrp.ppt
Eigrp.ppt
Edgardo Scrimaglia13.3K vues
MikroTik & RouterOSMikroTik & RouterOS
MikroTik & RouterOS
Faelix Ltd1.5K vues
DHCPDHCP
DHCP
selvakumar_b1985526 vues
OSPF BasicsOSPF Basics
OSPF Basics
Martin Bratina9K vues
IMS Authentication with AKAv1 and AKAv2 IMS Authentication with AKAv1 and AKAv2
IMS Authentication with AKAv1 and AKAv2
mohammad norozzudegan776 vues
Mobile transportlayerMobile transportlayer
Mobile transportlayer
Rahul Hada22.3K vues
Network LayerNetwork Layer
Network Layer
Dr Shashikant Athawale9.5K vues
Mikro tik advanced trainingMikro tik advanced training
Mikro tik advanced training
Jignesh H. Bhalsod4.8K vues
CS6551 COMPUTER NETWORKSCS6551 COMPUTER NETWORKS
CS6551 COMPUTER NETWORKS
Kathirvel Ayyaswamy2.8K vues
GRE (Generic Routing Encapsulation)GRE (Generic Routing Encapsulation)
GRE (Generic Routing Encapsulation)
NetProtocol Xpert2.1K vues
IP Sec - Basic ConceptsIP Sec - Basic Concepts
IP Sec - Basic Concepts
Avadhesh Agrawal1.9K vues
CCNA Course Training PresentationCCNA Course Training Presentation
CCNA Course Training Presentation
Rohit Singh5.5K vues
Socket programmingSocket programming
Socket programming
Muhammad Fouad Ilyas Siddiqui2.2K vues
Presentation on arp protocolPresentation on arp protocol
Presentation on arp protocol
Mohd. Ahmad Siddiqi4.9K vues

En vedette

Application Layer Application Layer
Application Layer Dr Shashikant Athawale
25.3K vues39 diapositives
Chapter2 ApplicationChapter2 Application
Chapter2 ApplicationDiego Corrales
4.7K vues115 diapositives
socket programming socket programming
socket programming prashantzagade
556 vues7 diapositives
Application layer chapter-9Application layer chapter-9
Application layer chapter-9Student
646 vues91 diapositives
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
15.1K vues63 diapositives

En vedette(15)

Application Layer Application Layer
Application Layer
Dr Shashikant Athawale25.3K vues
QSpiders - Dod ModelQSpiders - Dod Model
QSpiders - Dod Model
Qspiders - Software Testing Training Institute377 vues
Chapter2 ApplicationChapter2 Application
Chapter2 Application
Diego Corrales4.7K vues
socket programming socket programming
socket programming
prashantzagade556 vues
Application layer chapter-9Application layer chapter-9
Application layer chapter-9
Student646 vues
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute15.1K vues
Micro Programmed Control UnitMicro Programmed Control Unit
Micro Programmed Control Unit
Kamal Acharya34.7K vues
Lecture application layerLecture application layer
Lecture application layer
Hasam Panezai14.2K vues
File transfer protocol (ftp)File transfer protocol (ftp)
File transfer protocol (ftp)
Cort102616.7K vues
Ports  & sockets Ports  & sockets
Ports & sockets
myrajendra21.6K vues
File Transfer ProtocolFile Transfer Protocol
File Transfer Protocol
guest029bcd122.8K vues
Socket Programming TutorialSocket Programming Tutorial
Socket Programming Tutorial
Jignesh Patel36.6K vues
Microprogram Control Microprogram Control
Microprogram Control
Anuj Modi54.2K vues
The Data Link LayerThe Data Link Layer
The Data Link Layer
robbbminson13.7K vues

Similaire à Application Layer and Socket Programming

Unit 8 JavaUnit 8 Java
Unit 8 Javaarnold 7490
1.5K vues31 diapositives
Socket programmingSocket programming
Socket programmingDivya Sharma
891 vues15 diapositives
Socket ProgrammingSocket Programming
Socket ProgrammingCEC Landran
6.5K vues27 diapositives
03 sockets03 sockets
03 socketsPavan Illa
528 vues74 diapositives
Sockets Sockets
Sockets Gopaiah Sanaka
157 vues33 diapositives

Similaire à Application Layer and Socket Programming(20)

Unit 8 JavaUnit 8 Java
Unit 8 Java
arnold 74901.5K vues
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
Tushar B Kute3K vues
Socket programmingSocket programming
Socket programming
Divya Sharma891 vues
Socket ProgrammingSocket Programming
Socket Programming
CEC Landran6.5K vues
03 sockets03 sockets
03 sockets
Pavan Illa528 vues
Sockets Sockets
Sockets
Gopaiah Sanaka157 vues
Os 2Os 2
Os 2
university of Gujrat, pakistan54 vues
Network Prog.pptNetwork Prog.ppt
Network Prog.ppt
EloOgardo4 vues
Net Programming.pptNet Programming.ppt
Net Programming.ppt
EloAcubaOgardo4 vues
Md13 networkingMd13 networking
Md13 networking
Rakesh Madugula538 vues
Unit-4 networking basics in javaUnit-4 networking basics in java
Unit-4 networking basics in java
Amol Gaikwad228 vues
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli1K vues
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute7 vues
Lan chat systemLan chat system
Lan chat system
Wipro20.7K vues
Network SocketsNetwork Sockets
Network Sockets
Peter R. Egli7.6K vues
Sockets Sockets
Sockets
babu4b4u269 vues
FirewallFirewall
Firewall
Manikyala Rao3.5K vues

Plus de elliando dias(20)

Clojurescript slidesClojurescript slides
Clojurescript slides
elliando dias4.4K vues
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
elliando dias32.1K vues
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
elliando dias5.9K vues
Javascript LibrariesJavascript Libraries
Javascript Libraries
elliando dias1.8K vues
Ragel talkRagel talk
Ragel talk
elliando dias2.1K vues
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
elliando dias3.7K vues
Minicurso arduinoMinicurso arduino
Minicurso arduino
elliando dias1.3K vues
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
elliando dias2.2K vues
RangoRango
Rango
elliando dias1.2K vues
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
elliando dias1.6K vues
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
elliando dias1K vues

Application Layer and Socket Programming

  • 1. 15-441: Computer Networking Lecture 3: Application Layer and Socket Programming
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. Transport Service Requirements of Common Apps no loss no loss no loss loss-tolerant loss-tolerant loss-tolerant no loss elastic elastic elastic audio: 5Kb-1Mb video:10Kb-5Mb same as above few Kbps elastic no no no yes, 100’s msec yes, few secs yes, 100’s msec yes and no file transfer e-mail web documents real-time audio/ video stored audio/video interactive games financial apps Application Data loss Bandwidth Time Sensitive
  • 10.
  • 11. Server and Client TCP/UDP IP Ethernet Adapter Server TCP/UDP IP Ethernet Adapter Clients Server and Client exchange messages over the network through a common Socket API Socket API hardware kernel space user space ports
  • 12.
  • 13.
  • 14. Network Addressing Analogy 412-268-8000 ext.123 Central Number Applications/Servers Web Port 80 Mail Port 25 Exchange Area Code 412-268-8000 ext.654 IP Address Network No. Host Number Telephone No 15-441 Students Clients Professors at CMU Network Programming Telephone Call Port No. Extension
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34. Review: TCP Client-Server Interaction socket() bind() listen() accept() write() read() read() TCP Server close() socket() TCP Client connect() write() read() close() connection establishment data request data reply end-of-file notification from UNIX Network Programming Volume 1, figure 4.1
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42. Review: UDP Client-Server Interaction socket() bind() recvfrom() sendto() UDP Server socket() UDP Client sendto() recvfrom() close() blocks until datagram received from a client data request data reply from UNIX Network Programming Volume 1, figure 8.1
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48. TCP IP Ethernet Adapter Web Server Port 80 How can a a web server manage multiple connections simultaneously? Port 8001 More Details About a Web Server
  • 49.
  • 50. A Few Programming Notes: Representing Packets 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Type | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length | Checksum | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Type: 4-byte integer Length: 2-byte integer Checksum: 2-byte integer Address: 4-byte IP address
  • 51. A Few Programming Notes: Building a Packet in a Buffer struct packet { u_int32_t type; u_int16_t length; u_int16_t checksum; u_int32_t address; }; /* ================================================== */ char buf[1024]; struct packet *pkt; pkt = (struct packet*) buf; pkt->type = htonl (1); pkt->length = htons (2); pkt->checksum = htons (3); pkt->address = htonl (4);
  • 52.