SlideShare une entreprise Scribd logo
1  sur  52
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]

Contenu connexe

Tendances (20)

Socket programming
Socket programmingSocket programming
Socket programming
 
The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecture
 
TCP/IP Network ppt
TCP/IP Network pptTCP/IP Network ppt
TCP/IP Network ppt
 
Address resolution protocol (ARP)
Address resolution protocol (ARP)Address resolution protocol (ARP)
Address resolution protocol (ARP)
 
Socket programming
Socket programmingSocket programming
Socket programming
 
TCP and UDP
TCP and UDP TCP and UDP
TCP and UDP
 
IPV4 vs IPV6
IPV4 vs IPV6IPV4 vs IPV6
IPV4 vs IPV6
 
Link state protocols.ppt
Link state protocols.pptLink state protocols.ppt
Link state protocols.ppt
 
TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)
TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)
TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)
 
Socket Programming In Python
Socket Programming In PythonSocket Programming In Python
Socket Programming In Python
 
Ppt of socket
Ppt of socketPpt of socket
Ppt of socket
 
Socket Programming with Python
Socket Programming with PythonSocket Programming with Python
Socket Programming with Python
 
IP Address - IPv4 & IPv6
IP Address - IPv4 & IPv6IP Address - IPv4 & IPv6
IP Address - IPv4 & IPv6
 
TFTP - Trivial File Transfer Protocol
TFTP - Trivial File Transfer ProtocolTFTP - Trivial File Transfer Protocol
TFTP - Trivial File Transfer Protocol
 
IP Address
IP AddressIP Address
IP Address
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 
Subnetting Presentation
Subnetting PresentationSubnetting Presentation
Subnetting Presentation
 
Socket programming
Socket programmingSocket programming
Socket programming
 
CCNA v6.0 ITN - Chapter 03
CCNA v6.0 ITN - Chapter 03CCNA v6.0 ITN - Chapter 03
CCNA v6.0 ITN - Chapter 03
 
Access Control List & its Types
Access Control List & its TypesAccess Control List & its Types
Access Control List & its Types
 

En vedette

Application layer chapter-9
Application layer chapter-9Application layer chapter-9
Application layer chapter-9Student
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
Micro Programmed Control Unit
Micro Programmed Control UnitMicro Programmed Control Unit
Micro Programmed Control UnitKamal Acharya
 
Lecture application layer
Lecture application layerLecture application layer
Lecture application layerHasam Panezai
 
File transfer protocol (ftp)
File transfer protocol (ftp)File transfer protocol (ftp)
File transfer protocol (ftp)Cort1026
 
Physical Layer of ISO-OSI model and Devices
Physical Layer of ISO-OSI model and DevicesPhysical Layer of ISO-OSI model and Devices
Physical Layer of ISO-OSI model and DevicesShahid Khan
 
Ports & sockets
Ports  & sockets Ports  & sockets
Ports & sockets myrajendra
 
File Transfer Protocol
File Transfer ProtocolFile Transfer Protocol
File Transfer Protocolguest029bcd
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming TutorialJignesh Patel
 
Microprogram Control
Microprogram Control Microprogram Control
Microprogram Control Anuj Modi
 
The Data Link Layer
The Data Link LayerThe Data Link Layer
The Data Link Layerrobbbminson
 

En vedette (15)

Application Layer
Application Layer Application Layer
Application Layer
 
QSpiders - Dod Model
QSpiders - Dod ModelQSpiders - Dod Model
QSpiders - Dod Model
 
Chapter2 Application
Chapter2 ApplicationChapter2 Application
Chapter2 Application
 
socket programming
socket programming socket programming
socket programming
 
Application layer chapter-9
Application layer chapter-9Application layer chapter-9
Application layer chapter-9
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Micro Programmed Control Unit
Micro Programmed Control UnitMicro Programmed Control Unit
Micro Programmed Control Unit
 
Lecture application layer
Lecture application layerLecture application layer
Lecture application layer
 
File transfer protocol (ftp)
File transfer protocol (ftp)File transfer protocol (ftp)
File transfer protocol (ftp)
 
Physical Layer of ISO-OSI model and Devices
Physical Layer of ISO-OSI model and DevicesPhysical Layer of ISO-OSI model and Devices
Physical Layer of ISO-OSI model and Devices
 
Ports & sockets
Ports  & sockets Ports  & sockets
Ports & sockets
 
File Transfer Protocol
File Transfer ProtocolFile Transfer Protocol
File Transfer Protocol
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming Tutorial
 
Microprogram Control
Microprogram Control Microprogram Control
Microprogram Control
 
The Data Link Layer
The Data Link LayerThe Data Link Layer
The Data Link Layer
 

Similaire à Application Layer and Socket Programming

Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in JavaTushar B Kute
 
Socket programming
Socket programmingSocket programming
Socket programmingDivya Sharma
 
Network Prog.ppt
Network Prog.pptNetwork Prog.ppt
Network Prog.pptEloOgardo
 
Unit-4 networking basics in java
Unit-4 networking basics in javaUnit-4 networking basics in java
Unit-4 networking basics in javaAmol Gaikwad
 
16.) layer 3 (basic tcp ip routing)
16.) layer 3 (basic tcp ip routing)16.) layer 3 (basic tcp ip routing)
16.) layer 3 (basic tcp ip routing)Jeff Green
 
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jbCN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jbPRADEEPERUKULLA2
 
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونیMohammad Reza Kamalifard
 
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjjCN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjjPRADEEPERUKULLA2
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
Network Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxNetwork Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxssuser23035c
 
Lan chat system
Lan chat systemLan chat system
Lan chat systemWipro
 

Similaire à Application Layer and Socket Programming (20)

Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
 
Socket programming
Socket programmingSocket programming
Socket programming
 
03 sockets
03 sockets03 sockets
03 sockets
 
Sockets
Sockets Sockets
Sockets
 
Os 2
Os 2Os 2
Os 2
 
Network Prog.ppt
Network Prog.pptNetwork Prog.ppt
Network Prog.ppt
 
Net Programming.ppt
Net Programming.pptNet Programming.ppt
Net Programming.ppt
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Unit-4 networking basics in java
Unit-4 networking basics in javaUnit-4 networking basics in java
Unit-4 networking basics in java
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
16.) layer 3 (basic tcp ip routing)
16.) layer 3 (basic tcp ip routing)16.) layer 3 (basic tcp ip routing)
16.) layer 3 (basic tcp ip routing)
 
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jbCN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
 
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
 
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjjCN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Network Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxNetwork Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptx
 
Lan chat system
Lan chat systemLan chat system
Lan chat system
 
Network Sockets
Network SocketsNetwork Sockets
Network Sockets
 
Sockets
Sockets Sockets
Sockets
 

Plus de elliando dias

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slideselliando dias
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScriptelliando dias
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structureselliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de containerelliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agilityelliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Librarieselliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Webelliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduinoelliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorceryelliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Designelliando dias
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makeselliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebookelliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Studyelliando dias
 

Plus de elliando dias (20)

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
 
Geometria Projetiva
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
 
Ragel talk
Ragel talkRagel talk
Ragel talk
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
 
Minicurso arduino
Minicurso arduinoMinicurso arduino
Minicurso arduino
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
 
Rango
RangoRango
Rango
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
 

Dernier

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 

Dernier (20)

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

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.