chapter 2 outline n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Chapter 2 outline PowerPoint Presentation
Download Presentation
Chapter 2 outline

Loading in 2 Seconds...

play fullscreen
1 / 12

Chapter 2 outline - PowerPoint PPT Presentation


  • 59 Views
  • Uploaded on

2.1 Principles of app layer protocols 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail 2.5 DNS. 2.6 Socket programming with TCP 2.7 Socket programming with UDP 2.8 Building a Web server 2.9 Content distribution Network Web caching Content distribution networks P2P file sharing.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Chapter 2 outline' - lave


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
chapter 2 outline
2.1 Principles of app layer protocols

2.2 Web and HTTP

2.3 FTP

2.4 Electronic Mail

2.5 DNS

2.6 Socket programming with TCP

2.7 Socket programming with UDP

2.8 Building a Web server

2.9 Content distribution

Network Web caching

Content distribution networks

P2P file sharing

Chapter 2 outline

2: Application Layer

socket programming

An application-created,

OS-controlled interface (a “door”) into which

an application process can both send and

receive messages to/from another application process

socket

Socket programming

Goal: learn how to build client/server applications using sockets

Socket API

  • introduced in BSD4.1 UNIX, 1981
  • explicitly created, used, released by apps
  • client/server paradigm
  • two types of transport service via socket API:
    • unreliable datagram
    • reliable, byte stream-oriented

2: Application Layer

socket programming using tcp

process

process

TCP with

buffers,

variables

TCP with

buffers,

variables

socket

socket

Socket programming using TCP

Socket: a door between an application process and end-to-end transport protocol (UDP or TCP)

TCP service: reliable transfer of bytesfrom one process to another

controlled by

application

developer

controlled by

application

developer

controlled by

operating

system

controlled by

operating

system

Internet

host or

server

host or

server

2: Application Layer

socket programming with tcp
Client must contact server

server process must first be running

server must have created socket (door) that welcomes client’s contact - listen

Client contacts server by:

creating client-local TCP socket

specifying IP address, port number of server process

trying to connect: client TCP establishes connection to server TCP

When contacted by client, server TCP creates new socket for server process to communicate with client

allows server to talk with multiple clients

source port numbers used to distinguish clients (more in Chap 3)?

TCP provides reliable, in-order

transfer of bytes (“pipe”)

between client and server

application viewpoint

Socket programming with TCP

2: Application Layer

client server socket interaction tcp

create socket,

connect to “hostname”, port=x

create socket,

port=x, for

incoming request:

socket(),

connect()

socket(), bind(), listen()

TCP

connection setup

wait for incoming

connection request

accept()

send request

write()

read request

read()

write reply

write()

read reply from

read()

close

close()

close

close()

Client/server socket interaction: TCP

Server (running on “hostname”)

Client

2: Application Layer

berkeley socket api for tcp
Berkeley Socket API for TCP:

Server

Client

int socket(int family, int type,

int protocol);

int bind(int sockfd,

struct sockaddr *myaddr,

int addrlen);

int listen(int sockfd, int backlog);

int socket(…);

int connect(int sockfd,

struct sockaddr *servaddr, int addrlen);

int accept(int sockfd,

struct sockaddr *peer,

int *addrlen);

int send(int sockfd, char *buff, int nbytes, int flags);

int recv(int sockfd, char *buff, int nbytes, int flags);

int send(…);

int recv(…);

int close(int fd);

int close(…);

2: Application Layer

sketch of a tcp server
Sketch of a TCP Server

if (( sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)

perror(“server: can’t open stream socket”);

bzero((char *)&serv_addr, sizeof(serv_addr));

serv_addr.sin_family = AF_INET;

serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);

serv_addr.sin_port = htons(SERV_TCP_PORT);

if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)

perror(“server: can’t bind local address”);

listen(sockfd, 5);

while(1){

newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);

/* receive request from client, send reply */

close(newsockfd);

}

2: Application Layer

sketch of a tcp client
Sketch of a TCP Client

bzero((char *)&serv_addr, sizeof(serv_addr));

serv_addr.sin_family = AF_INET;

serv_addr.sin_addr.s_addr = htonl(SERVER_HOST_IP_ADDRESS);

serv_addr.sin_port = htons(SERVER_TCP_PORT);

if (( sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)

perror(“client: can’t open stream socket”);

if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)

perror(“client: cannot connect to server”);

/* send request to server, receive reply */

close(sockfd);

}

2: Application Layer

socket programming with udp
UDP: no “connection” between client and server

no handshaking

sender explicitly attaches IP address and port of destination to each packet

server must extract IP address, port of sender from received packet

UDP: transmitted data may be received out of order, or lost

UDP provides unreliable transfer

of groups of bytes (“datagrams”)

between client and server

application viewpoint

Socket programming with UDP

2: Application Layer

client server socket interaction udp

Client

create socket,

port=x, for

incoming request:

socket(), bind()

create socket,

Create data + (“hostname”, port=x)

send datagram request

sendto()

socket()

read request from

recvfrom()

write reply

sendto()

specifying client

host address,

port number

read reply

recvfrom()

close

close()

Client/server socket interaction: UDP

Server (running on “hosname”)

2: Application Layer

berkeley socket api for udp
Berkeley Socket API for UDP:

Server

Client

int socket(int family, int type,

int protocol);

int bind(int sockfd,

struct sockaddr *myaddr,

int addrlen);

int socket(…);

int bind(…);

int sendto(int sockfd, char *buff, int nbytes, int flags,

struct sockaddr *to, int addrlen);

int recvfrom(int sockfd, char *buff, int nbytes, int flags,

struct sockaddr *from,

int *addrlen);

int sendto(…);

int recvfrom(…);

rint close(int fd);

int close(…);

2: Application Layer

building a simple web server
handles HTTP/1.0 requests

accepts a request

parses header

obtains requested file from server’s file system

creates HTTP response message:

header lines + file

sends response to client

Repeat for another request

creates a transaction log

(you) show statistics (delay, size, elapsed time of different phases, etc).

see assignment

put some files in your directory (both small/KB and large/MB objects)

after creating server, you can request file using a browser (e.g. IE explorer)

will be tested by other people.

see assignment

http://java.sun.com

Building a simple Web server

2: Application Layer