SlideShare uma empresa Scribd logo
1 de 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]

Mais conteúdo relacionado

Mais procurados

Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1CAVC
 
Chap2. ipv4-arp-icmp
Chap2. ipv4-arp-icmpChap2. ipv4-arp-icmp
Chap2. ipv4-arp-icmp東原 李
 
IMS Naming Identity
IMS Naming IdentityIMS Naming Identity
IMS Naming IdentityKent Loh
 
Subnet Masks
Subnet MasksSubnet Masks
Subnet Masksswascher
 
IP, DNS and MAC concepts
IP, DNS and MAC conceptsIP, DNS and MAC concepts
IP, DNS and MAC conceptsIrshaad Abdool
 
TCP- Transmission Control Protocol
TCP-  Transmission Control Protocol TCP-  Transmission Control Protocol
TCP- Transmission Control Protocol Akhil .B
 
Socket programming
Socket programmingSocket programming
Socket programmingharsh_bca06
 
Linux Networking Commands
Linux Networking CommandsLinux Networking Commands
Linux Networking Commandstmavroidis
 
Address resolution protocol
Address resolution protocolAddress resolution protocol
Address resolution protocolasimnawaz54
 
What is Socket Programming in Python | Edureka
What is Socket Programming in Python | EdurekaWhat is Socket Programming in Python | Edureka
What is Socket Programming in Python | EdurekaEdureka!
 
Mail Server Configuration with Cisco Packet Tracer
Mail Server Configuration with Cisco Packet TracerMail Server Configuration with Cisco Packet Tracer
Mail Server Configuration with Cisco Packet TracerMaksudujjaman
 
Forouzan-ch19-Network-Layer-Logical-Addressing.ppt
Forouzan-ch19-Network-Layer-Logical-Addressing.pptForouzan-ch19-Network-Layer-Logical-Addressing.ppt
Forouzan-ch19-Network-Layer-Logical-Addressing.pptJayaprasanna4
 
Transport layer udp and tcp network
Transport layer udp and tcp networkTransport layer udp and tcp network
Transport layer udp and tcp networkHamzahMohammed4
 

Mais procurados (20)

Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1
 
Chap2. ipv4-arp-icmp
Chap2. ipv4-arp-icmpChap2. ipv4-arp-icmp
Chap2. ipv4-arp-icmp
 
Dhcp ppt
Dhcp pptDhcp ppt
Dhcp ppt
 
IP Addressing
IP AddressingIP Addressing
IP Addressing
 
Npc08
Npc08Npc08
Npc08
 
IMS Naming Identity
IMS Naming IdentityIMS Naming Identity
IMS Naming Identity
 
Subnet Masks
Subnet MasksSubnet Masks
Subnet Masks
 
Files in php
Files in phpFiles in php
Files in php
 
Http-protocol
Http-protocolHttp-protocol
Http-protocol
 
IP, DNS and MAC concepts
IP, DNS and MAC conceptsIP, DNS and MAC concepts
IP, DNS and MAC concepts
 
TCP- Transmission Control Protocol
TCP-  Transmission Control Protocol TCP-  Transmission Control Protocol
TCP- Transmission Control Protocol
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Linux Networking Commands
Linux Networking CommandsLinux Networking Commands
Linux Networking Commands
 
IP Routing
IP RoutingIP Routing
IP Routing
 
Address resolution protocol
Address resolution protocolAddress resolution protocol
Address resolution protocol
 
What is Socket Programming in Python | Edureka
What is Socket Programming in Python | EdurekaWhat is Socket Programming in Python | Edureka
What is Socket Programming in Python | Edureka
 
Mail Server Configuration with Cisco Packet Tracer
Mail Server Configuration with Cisco Packet TracerMail Server Configuration with Cisco Packet Tracer
Mail Server Configuration with Cisco Packet Tracer
 
Forouzan-ch19-Network-Layer-Logical-Addressing.ppt
Forouzan-ch19-Network-Layer-Logical-Addressing.pptForouzan-ch19-Network-Layer-Logical-Addressing.ppt
Forouzan-ch19-Network-Layer-Logical-Addressing.ppt
 
Transport layer udp and tcp network
Transport layer udp and tcp networkTransport layer udp and tcp network
Transport layer udp and tcp network
 

Destaque

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
 
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
 

Destaque (14)

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
 
Microprogram Control
Microprogram Control Microprogram Control
Microprogram Control
 
The Data Link Layer
The Data Link LayerThe Data Link Layer
The Data Link Layer
 

Semelhante a 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
 

Semelhante a 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
 

Mais 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
 

Mais 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
 

Último

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 

Último (20)

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 

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.