Top Banner
Chapter 14 Application Layer and Client-Server Model
42
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chapter 14 Application Layer and Client-Server Model.

Chapter 14

Application Layerand

Client-ServerModel

Page 2: Chapter 14 Application Layer and Client-Server Model.

Figure 14-1

Page 3: Chapter 14 Application Layer and Client-Server Model.

Client-Server ModelClient-Server Model

Page 4: Chapter 14 Application Layer and Client-Server Model.

Figure 14-3

Page 5: Chapter 14 Application Layer and Client-Server Model.

ConcurrenciaConcurrencia

Type of Running in Clientes Iteratively: one-by-one Concurrently: at the same time

Concurrency in Services: Conectionless Iterative Server: from the

same cliente of from different clients (i.e. UDP)

Conection-Oriented Concurrent Server: serves many clients at the same time.

Page 6: Chapter 14 Application Layer and Client-Server Model.

Conectionless Iterative ServerConectionless Iterative Server

Page 7: Chapter 14 Application Layer and Client-Server Model.

Conection-Oriented Concurrent ServerConection-Oriented Concurrent Server

Page 8: Chapter 14 Application Layer and Client-Server Model.

ProcesosProcesos

Concepto Identificación Creación

Page 9: Chapter 14 Application Layer and Client-Server Model.

IdentificaciónIdentificación

Page 10: Chapter 14 Application Layer and Client-Server Model.

Figure 14-10

Page 11: Chapter 14 Application Layer and Client-Server Model.

CreaciónCreación

Page 12: Chapter 14 Application Layer and Client-Server Model.

Figure 14-12

Page 13: Chapter 14 Application Layer and Client-Server Model.

Figure 14-13

Page 14: Chapter 14 Application Layer and Client-Server Model.

Figure 14-14

Page 15: Chapter 14 Application Layer and Client-Server Model.

Figure 14-15

Page 16: Chapter 14 Application Layer and Client-Server Model.

Figure 14-16

Page 17: Chapter 14 Application Layer and Client-Server Model.

Chapter 24

SocketInterface

Page 18: Chapter 14 Application Layer and Client-Server Model.

Socket TypesSocket Types

Page 19: Chapter 14 Application Layer and Client-Server Model.

Conectionless Iterative ServerConectionless Iterative Server

Page 20: Chapter 14 Application Layer and Client-Server Model.

Conection-Oriented Concurren ServerConection-Oriented Concurren Server

Page 21: Chapter 14 Application Layer and Client-Server Model.

Figure 24-26 (repeated), Part I

Page 22: Chapter 14 Application Layer and Client-Server Model.

Figure 24-26 (repeated), Part II

Page 23: Chapter 14 Application Layer and Client-Server Model.

Figure 24-27, Part I

Page 24: Chapter 14 Application Layer and Client-Server Model.

Figure 24-27, Part II

Page 25: Chapter 14 Application Layer and Client-Server Model.

Sockets used for datagramsSockets used for datagrams

ServerAddress and ClientAddress are socket addresses

Sending a message Receiving a message

bind(s, ClientAddress)

sendto(s, "message", ServerAddress)

bind(s, ServerAddress)

amount = recvfrom(s, buffer, from)

s = socket(AF_INET, SOCK_DGRAM, 0)s = socket(AF_INET, SOCK_DGRAM, 0)

Page 26: Chapter 14 Application Layer and Client-Server Model.

Sockets used for streamsSockets used for streams

Requesting a connection Listening and accepting a connection

bind(s, ServerAddress);listen(s,5);

sNew = accept(s, ClientAddress);

n = read(sNew, buffer, amount)

s = socket(AF_INET, SOCK_STREAM,0)

connect(s, ServerAddress)

write(s, "message", length)

s = socket(AF_INET, SOCK_STREAM,0)

ServerAddress and ClientAddress are socket addresses

Page 27: Chapter 14 Application Layer and Client-Server Model.

#include <sys/types.h>#include <sys/socket.h>#include <netdb.h>#include <netinet/in.h>#include <stdio.h>#include <string.h>

#define MAXBUF 256#define PORT 2000void main(void){

char buf[MAXBUF];int activeSocket;int remoteAddrLen;struct sockaddr_in remoteAddr;struct sockaddr_in localAddr;struct hostent *hptr;

Page 28: Chapter 14 Application Layer and Client-Server Model.

activeSocket = socket(AF_INET, SOCK_DGRAM, 0);memset(&remoteAddr, 0,sizeof(remoteAddr));remoteAddr.sin_family =AF_INET;remoteAddr.sin_port=htons(PORT);hptr=gethostbyname("a-domain-name");memcpy((char*)&remoteAddr.sin_addr.s_addr,hptr->h_addr_list[0],hptr-

>h_length);connect(activeSocket, &remoteAddr, sizeof(remoteAddr));memset(buf, 0, MAXBUF);remoteAddrLen = sizeof(remoteAddr);while { sendto(activeSocket, buf, sizeof(buf), 0,

&remoteAddr,sizeof(remoteAddr$ memset(buf, 0, sizof(buf)); recvfrom(activeSocket, buf, MAXBUF, 0, &remoteAddr,&remoteAddrLen); printf("%s\n", buf); memset(buf, 0, sizeof(buf));};

close(activeSocket);}

Page 29: Chapter 14 Application Layer and Client-Server Model.

AnexoAnexo

Page 30: Chapter 14 Application Layer and Client-Server Model.

Socket System CallsSocket System Calls

Page 31: Chapter 14 Application Layer and Client-Server Model.

Figure 24-18

Page 32: Chapter 14 Application Layer and Client-Server Model.

Figure 24-21

Page 33: Chapter 14 Application Layer and Client-Server Model.

Data typesData types

Page 34: Chapter 14 Application Layer and Client-Server Model.

Internal Sockets Address StructureInternal Sockets Address Structure

Page 35: Chapter 14 Application Layer and Client-Server Model.

Sockets StructureSockets Structure

Page 36: Chapter 14 Application Layer and Client-Server Model.

Byte OrderingByte Ordering

Page 37: Chapter 14 Application Layer and Client-Server Model.

Figure 24-8

Page 38: Chapter 14 Application Layer and Client-Server Model.
Page 39: Chapter 14 Application Layer and Client-Server Model.

Order TranslationOrder Translation

Page 40: Chapter 14 Application Layer and Client-Server Model.

Byte Manipulation functionsByte Manipulation functions

Page 41: Chapter 14 Application Layer and Client-Server Model.

Information About Remote HostInformation About Remote Host

Page 42: Chapter 14 Application Layer and Client-Server Model.

Figure 24-14