Server types concurrent, connectionless very uncommon a process - - PDF document

server types
SMART_READER_LITE
LIVE PREVIEW

Server types concurrent, connectionless very uncommon a process - - PDF document

TCP week 8 5/12/02 1 Clients & Servers Client: in general, an application that initiates a peer-to-peer communication end users usually invoke client software Server: waits for incoming communication requests from a client


slide-1
SLIDE 1

1

5/12/02 1

TCP

week 8

5/12/02 2

Clients & Servers

  • Client:

ß in general, an application that initiates a peer-to-peer communication ß end users usually invoke client software

  • Server:

ß waits for incoming communication requests from a client ß performs necessary computation and ß probably returns a result

5/12/02 3

Concurrent Vs. Iterative

  • concurrent-server

ß handles multiple requests at one time

  • iterative-server

ß process one request at a time

slide-2
SLIDE 2

2

5/12/02 4

Connection - [oriented | less]

  • Connectionless

ß UDP - User Datagram Protocol ß the burden of the data integrity is on the application

  • Connection-oriented

ß TCP - Transport Control Protocol ß the program is free to deal with higher things

5/12/02 5

types of server/client

concurrent connection-oriented concurrent connectionless iterative connection-oriented iterative connectionless

5/12/02 6

Server types

  • iterative, connectionless

ß the most common

  • usually stateless
  • trivial amount of processing
  • iterative, connection-oriented

ß less common

  • trivial amount of data but
  • need reliable transport
slide-3
SLIDE 3

3

5/12/02 7

Server types …

  • concurrent, connectionless

ß very uncommon

  • a process is created for each request
  • actually tftpd is one
  • concurrent, connection-oriented

ß the most common

  • reliable transport
  • usually used by long living activities

5/12/02 8

TCP: Transmission Control Protocol

  • connection oriented

ß exactly two end points.

  • no broadcast/multicast

ß the two applications must establish a TCP connection with each other before they can exchange data.

  • reliable
  • byte stream

ß 8-bit bytes with no interpretation ß there are no record boundaries

5/12/02 9

reliable …

  • data is broken up into best size chunks

ß the unit of information passed by TCP to IP is called a segment

  • each segment sent has a timer

ß when the timer expires before an acknowledgment is received, the segment is retransmitted

  • when data is received, an acknowledgment is sent

ß but not immediately

  • the data and header have a checksum

ß a segment with a bad/invalid checksum is dropped, the sender times out and retransmits

slide-4
SLIDE 4

4

5/12/02 10

reliable …

  • preserves sequence

ß IP datagrams can arrive out of order ß segments are resequenced if necessary

  • drops duplicates

ß since IP datagrams can get duplicated.

  • flow control

ß each end of a TCP connection has a finite amount of buffer space ß the receiving side allows the other end to send as much data as it has buffer for.

5/12/02 11

IP header TCP header TCP data

IP datagram TCP segment

TCP Encapsulation

5/12/02 12

TCP Header

16-bit source port number 16-bit destination port number 32-bit sequence number 16-bit TCP checksum 16-bit urgent pointer

  • ptions (if any)

32-bit acknowledgment number 4-bit header length 6-bit flags 16-bit window size data (if any)

20 bytes max. 60 bytes

slide-5
SLIDE 5

5

5/12/02 13

TCP Header …

  • each segment contains a source and

destination port number

  • together with the source and destination

IP number from the IP header we get a unique identification of each connection

  • socket: IP address + port number
  • socket pair: source + destination sockets

5/12/02 14

TCP Header …

  • flags:

ß URG the urgent pointer is valid ß ACK the acknowledgement number is valid ß PSH the receiver should pass this data ASAP ß RST Reset the connection ß SYN Synchronize sequence number to init. connection ß FIN the sender has finished sending data

5/12/02 15

Connection Establishment

  • 1. the client sends a SYN segment specifying the

port # of the server it wants to connect to, and the client’s ISN - initial sequence number

  • 2. the server responds with its own SYN segment

containing the server’s ISN. The server also ACKs the client’s SYN by ACKing the client’s ISN+1

  • 3. the client must ACK this SYN from the server by

ACKing the server’s ISN+1

tree-way handshake:

slide-6
SLIDE 6

6

5/12/02 16

State Transition Diagram

Closed Listen

SYN_RCVD SYN_SENT Established passive open

active open recv: SYN send: SYN+ACK recv: ACK send: nothing data transfer state application: active open send: SYN recv: SYN+ACK send: ACK application: passive open send: nothing Client Server

5/12/02 17

Sliding window

1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 initial window window slides the sender can transmit all packets in the window without waiting for an acknowledgement

5/12/02 18

main(int cc, char **vv) { struct sockaddr_in srv; char buf[BUFSIZ], *addr; int sfd, n; bzero(&srv, sizeof(struct sockaddr_in)); addr = vv[1]; if((sfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { perror("socket"); exit(1); } if(!isdigit(*addr)) { struct hostent *hp; if((hp = gethostbyname(addr)) == NULL) { fprintf(stderr, "host '%s': not found\n", addr); exit(1); } memcpy((caddr_t *)&srv.sin_addr, hp->h_addr_list[0], hp->h_length); } else srv.sin_addr.s_addr = inet_addr(addr);

slide-7
SLIDE 7

7

5/12/02 19

srv.sin_family = AF_INET; srv.sin_port = htons(13); if(connect(sfd, (struct sockaddr *)&srv, sizeof(srv)) < 0) { perror("connect"); exit(1); } if(write(sfd, buf, 0) < 0) { perror("write"); exit(1); } n = read(sfd, buf, sizeof(buf)); if(n < 0) { perror("recvfrom"); exit(1); } printf("%.*s", n, buf); exit(0); }