Chapter 14 Application Layer and Client-Server Model.

42
Chapter 14 Application Layer and Client-Server Model

Transcript of Chapter 14 Application Layer and Client-Server Model.

Chapter 14

Application Layerand

Client-ServerModel

Figure 14-1

Client-Server ModelClient-Server Model

Figure 14-3

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.

Conectionless Iterative ServerConectionless Iterative Server

Conection-Oriented Concurrent ServerConection-Oriented Concurrent Server

ProcesosProcesos

Concepto Identificación Creación

IdentificaciónIdentificación

Figure 14-10

CreaciónCreación

Figure 14-12

Figure 14-13

Figure 14-14

Figure 14-15

Figure 14-16

Chapter 24

SocketInterface

Socket TypesSocket Types

Conectionless Iterative ServerConectionless Iterative Server

Conection-Oriented Concurren ServerConection-Oriented Concurren Server

Figure 24-26 (repeated), Part I

Figure 24-26 (repeated), Part II

Figure 24-27, Part I

Figure 24-27, Part II

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)

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

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

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);}

AnexoAnexo

Socket System CallsSocket System Calls

Figure 24-18

Figure 24-21

Data typesData types

Internal Sockets Address StructureInternal Sockets Address Structure

Sockets StructureSockets Structure

Byte OrderingByte Ordering

Figure 24-8

Order TranslationOrder Translation

Byte Manipulation functionsByte Manipulation functions

Information About Remote HostInformation About Remote Host

Figure 24-14