Chapter 14 Application Layer and Client-Server Model
Figure 14-1
Client-Server Model
Figure 14-3
Concurrencia 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 Server
Conection-Oriented Concurrent Server
Procesos Concepto Identificación Creación
Identificación
Figure 14-10
Creación
Figure 14-12
Figure 14-13
Figure 14-14
Figure 14-15
Figure 14-16
Chapter 24 Socket Interface
Socket Types
Conectionless Iterative Server
Conection-Oriented Concurren Server
Figure (repeated), Part I
Figure (repeated), Part II
Figure 24-27, Part I
Figure 24-27, Part II
Sockets used for datagrams ServerAddress and ClientAddress are socket addresses Sending a messageReceiving a message bind(s, ClientAddress) sendto(s, "message", ServerAddress) bind(s, ServerAddress) amount = recvfrom(s, buffer, from) s = socket(AF_INET, SOCK_DGRAM, 0)
Sockets used for streams Requesting a connectionListening 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 #define MAXBUF 256 #define PORT 2000 void 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); }
Anexo
Socket System Calls
Figure 24-18
Figure 24-21
Data types
Internal Sockets Address Structure
Sockets Structure
Byte Ordering
Figure 24-8
Order Translation
Byte Manipulation functions
Information About Remote Host
Figure 24-14