Docsity

Midterm Exam Review: Understanding Clients and Servers in TCP and UDP Protocols, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
Virginia Tech
Bradley Department of Electrical and Computer Engineering
ECE 4564: Network Application Design Fall 2008
Midterm Exam Topics
Overview of Networks and Services (lecture 2)
Distinguish between services, interfaces, and implementations related to protocols
Service- TCP: reliable, stream-oriented data transfer through a network. Independent of how it is
accessed (the interface) and how it is implemented.
Interface- accesses the data transport service. Defined as API (WinSock, BSD Unix Sockets). Different
APIs exist on same OS or may vary. Provides software interface.
Implementation- doesn’t affect interface or service. Different implementations of a protocol and service by
different vendors
Identify the functions and specify the operation of the key protocols in the TCP/IP
protocol suite, including IP, IPv6, UDP, and TCP.
TCP- Transport layer: byte-stream transfer, reliable, connection-oriented service, point-to-point service
only (unicast). Sliding window- flow control to adjust sending speed, window size varies depending on
buffer size and congestion. Connection established- Three way handshake
UDP- Transport layer: unreliable connection-less datagram service, point-to-point, multicast (1-to-many),
and broadcast (1-to-all). Guarantees no bit errors with checksum (doesn’t guarantee delivery or
order).
IP- Network layer: unreliable service, performs routing (RIP, OSPF, IS-IS, IGP, BGP). Fragmentation of
datagrams depending on MTU.
IPv6- Network layer: unreliable datagram delivery, no fragmentation, uses ICMP to tell host to send
smaller packets, can be used with existing Transport layer protocols, more addresses, security
required, stateful and stateless addressing configurations,
Network layer: ICMP, IGMP
Datalink layer: ARP, RARP
Identify the differences in transport layer services provided by TCP versus UDP and
select an appropriate protocol based on application characteristics.
TCP- Segmentation, error recovery, end to end flow control (avoids buffer overflow),
multiplexing/demultiplexing. Full duplex and buffered (accepts data and transmits when appropriate).
Busty bulk transfers, slow-start reduces throughput, extra overhead per segment
UDP- exchanges datagrams, not-buffered (transmits data immediately), full duplex. Limited to 64 kb
HTTP, FTP, Telnet, POP - TCP
Rwho, MBONE, Real Player, NFS (uses both now) - UDP
Overview of Network Applications (lecture 3, 4)
Describe the role of port numbers for network applications.
Distinguish between multiple applications on one host. Indicate particular underlying Transport protocol.
ECE 4564 Fall 2008 Midterm Exam Review Page 1 of 13
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Midterm Exam Review: Understanding Clients and Servers in TCP and UDP Protocols and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Virginia Tech Bradley Department of Electrical and Computer Engineering

ECE 4564: Network Application Design  Fall 2008

Midterm Exam Topics Overview of Networks and Services (lecture 2)Distinguish between services, interfaces, and implementations related to protocols Service- TCP: reliable, stream-oriented data transfer through a network. Independent of how it is accessed (the interface) and how it is implemented. Interface- accesses the data transport service. Defined as API (WinSock, BSD Unix Sockets). Different APIs exist on same OS or may vary. Provides software interface. Implementation- doesn’t affect interface or service. Different implementations of a protocol and service by different vendors  Identify the functions and specify the operation of the key protocols in the TCP/IP protocol suite, including IP, IPv6, UDP, and TCP. TCP- Transport layer: byte-stream transfer, reliable, connection-oriented service, point-to-point service only (unicast). Sliding window- flow control to adjust sending speed, window size varies depending on buffer size and congestion. Connection established- Three way handshake UDP- Transport layer: unreliable connection-less datagram service, point-to-point, multicast (1-to-many), and broadcast (1-to-all). Guarantees no bit errors with checksum (doesn’t guarantee delivery or order). IP- Network layer: unreliable service, performs routing (RIP, OSPF, IS-IS, IGP, BGP). Fragmentation of datagrams depending on MTU. IPv6- Network layer: unreliable datagram delivery, no fragmentation, uses ICMP to tell host to send smaller packets, can be used with existing Transport layer protocols, more addresses, security required, stateful and stateless addressing configurations, Network layer: ICMP, IGMP Datalink layer: ARP, RARP  Identify the differences in transport layer services provided by TCP versus UDP and select an appropriate protocol based on application characteristics. TCP- Segmentation, error recovery, end to end flow control (avoids buffer overflow), multiplexing/demultiplexing. Full duplex and buffered (accepts data and transmits when appropriate). Busty bulk transfers, slow-start reduces throughput, extra overhead per segment UDP- exchanges datagrams, not-buffered (transmits data immediately), full duplex. Limited to 64 kb HTTP, FTP, Telnet, POP - TCP Rwho, MBONE, Real Player, NFS (uses both now) - UDP Overview of Network Applications (lecture 3, 4)Describe the role of port numbers for network applications. Distinguish between multiple applications on one host. Indicate particular underlying Transport protocol.

Distinguish between clients and servers as determined by the transport protocol (TCP and UDP) and the application protocol. Client- Issues requests to server and accepts response. Server- Awaits requests and responds once received. Privileges: authentication, authorization, data security and privacy, protection Introduction to Network Application Design (lecture 4,7)Characterize client-server protocols with respect to being connection-oriented versus connectionless. Connection-oriented – usually TCP, connection overhead. Data correct, ordered, and not duplicated. Connectionless – sent to clients immediately, usually UDP. Data may not arrive, may be incorrect, duplicated, out of order  Characterize client-server protocols with respect to being stateful versus stateless. Stateful – servers maintain state information, examples: TELNET, FTP Stateless – servers keep no state information, examples: Finger, HTTP, NFS  Discuss design issues related to stateful and stateless application protocols. Issues: time-outs, duplicate requests/replies, system crashes, multiple clients, file-locking Stateless – must identify all information with each request, redundant, inefficient, but simplified Example: OPEN(/tmp/test.txt, “r”) READ(/tmp/test.txt, 0, 200) READ(/tmp/test.txt, 200, 200) Stateful – server provides handle to access state at the server, complex, deal with synchronization, TCP Example: Request: OPEN(/tmp/test.txt, “r”) Reply: OPEN(ok, 32) -- handle = 32 State: 32: /tmp/test.txt, 0, read Request: READ(32, 200) Reply: READ(ok, data) State: 32: /tmp/test.txt, 200, read  Characterize a server as being concurrent versus iterative. Concurrent – threaded, multiple clients (multiple requests same time) Iterative – not threaded, interacts with 1 client at 1 time (1 request at a time)  Compare and contrast the use of threads versus processes for concurrency.

CLR runs Microsoft Intermediate Language (MSIL) and uses just in time converter to convert to native code Platform Adaptation Layer (PAL) tailored for specific platform Client Algorithms and Examples (lecture 6)Describe how .NET classes and associated methods provide TCP and UDP clients with required functionality. TCP: Identify location of the server: IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse(szServIP), sServPort ); The GetHostByName() function retrieves host information corresponding to a host name from a host database The GetHostByAddr() function retrieves the host information corresponding to a network address. The GetHostName() function gets local computer’s host name. Allocate a socket: Socket sender = Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ) Connect to server: sender.Connect( remoteEP); UDP: Identify location of server: just like TCP Allocate a socket: Socket s = Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp ) No need to first connect with server  Relate Connect() and Shutdown() methods in the Socket class to TCP connect and disconnect operations. Connect(): Server is already accepting, Client calls connect -> SYN, Server sends SYN, ACK, Client sees connect success -> ACK, Server sees accept success Shutdown(): Client shutdowns send -> FIN, Server receives and shows close -> ACK -> Data, Client sees shutdown return and receives rest of data, Server sends shutdown -> FIN, Client receives and shows close -> ACK, Server sees shutdown return.  Describe or analyze the basic operation of clients for both connection-oriented and connectionless application protocols. Connection oriented: buffer may not be full on return, need to continue to receive until all data is received (stream oriented), bytes received is 0 when remote end shuts down socket for sending byte[] msg = Encoding.ASCII.GetBytes("This is a test" ); int bytesSent = sender.Send(msg); int bytesRec = sender.Receive(bytes); string strRetPage = Encoding.ASCII.GetString(bytes,0,bytesRec));

while (bytesRec > 0) { bytesRec = sender.Receive(bytes,0, bytes.Length, SocketFlags.None); strRetPage = strRetPage + Encoding.ASCII.GetString(bytes, 0, bytesRec); } Connection-less: unreliable s.SendTo(msg, 0, msg.Length, SocketFlags.None, endPoint); s.ReceiveFrom(msg, 0, msg.Length, SocketFlags.None, ref senderRemote);  Analyze the operation of example DAYTIME, TIME, and ECHO clients. Daytime – port 13, sends daytime as character string, TCP: sends response once connection detected, UDP: sends daytime messages when arbitrary datagram received Time – port 37, time represented in Universal Coordinated Time (UCT), 32-bit integer that is number of seconds since epoch (Jan 1 1970), rollover is Jan 19 2038, same response functionality as above, accuracy affected by network delay ( measure round trip delay, add half delay to received value) ECHO – port 7, test connectivity, debug protocols, find routing problems  Write pseudocode and/or C# code snippets for key functionality in synchronous TCP and UDP clients. Project 1 code Server Algorithms and Examples (lecture 7)Describe how .NET classes and associated methods provide TCP and UDP servers with required functionality. Iterative, TCP: Create a socket: Socket listener = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ); Bind to well-known address: IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, 6000); listener.Bind(localEndPoint); Place socket in passive mode: listener.Listen(4); Accept a connection from a client: Socket handler = listener.Accept(); Interact with client: int bytesSent = handler.Send(msg); int bytesRec = handler.Receive(bytes); Shutdown connection: handler.Shutdown(SocketShutdown.Both); handler.Close(); Iterative, UDP:

Conncurrent, UDP – multiple requests/clients serviced concurrently (no blocking periods), beginning a thread does have overhead (can dominate if time to respond to request is small, only a good choice if average processing time relative long) Concurrent, TCP – clients do not block while other clients are connected, beginning a thread has overhead (can dominate if connection time is small, good choice if average connection time is long relative to thread overhead) Concurrent – high time per request, high time per connection (TCP), high number of active clients, OS’s with low thread overhead creation, complex to share information among clients Iterative – low time per request, low time per connection (TCP), low number of active clients, easier to share information among clients  Analyze the operation of example DAYTIME, TIME, and ECHO servers. Time – iterative, connectionless design, server provides UTC time since epoch of Jan 1 1900. Daytime – iterative, connection oriented design, server blocks at connect until client connects, server just responds with character string once connection established. ECHO – multithreaded concurrent , connection oriented design, new thread created for each connection, worker function invoked for each thread  Write pseudocode and/or C# code snippets for key functionality in synchronous TCP and UDP servers. Project 1  Discuss causes of deadlock and analyze scenarios for possible deadlock. Occurs when client is blocked waiting on server, or server is blocked waiting on client. Examples: (1) Server accepted connection from client and is receiving but client never sends data. (2) Server is receiving a big buffer from client and is trying to reply, but blocks since client is not receiving because it is still sending its big buffer. Client blocks at send because it thinks server is not receiving. Server Design Techniques (lecture 8)Identify and compare different methods of concurrency management and control for servers. Demand-drive concurrency – one new thread per connection or request, one child thread per active connection/request, scales with demand, structurally simple, allows overlapped execution, can consume too many resources, can be slower than iterative due to overhead Pre-determined – pre-allocated threads, connection: only 1 child calls accept per request. level of concurrency and resource use is limited to N, no thread creation overhead during operation, rapidly empties a connectionless buffer, N is static so it can’t adjust with load, optimal N must be determined for each use Delayed – adaptive concurrency, delays creation of child threads, creates child thread only if processing time is large. Provides flexibility, but complex  Analyze, in a simple way, the performance of an iterative versus concurrent server design.

Concurrent – best case is full overlap. Example: T = time to create thread, C = time to process connection. Initial response times: Request 1 = T, Request 2 = 2T, Average = 3T/2. Completion times: Req 1 = T+C, Req 2 = 2T+C, Avg = C + 3T/2. Throughput = 1/T

  • worse case is no overlap. Example: Initial response times: Request 1 = 2T, Request 2 = 2T + C/3, Average = 2T + C/6. Completion times: Req 1 = 2T+5C/3, Req 2 = 2T+2C, Avg = ~2C + 2T. Throughput = 1/(T+C) Iterative – Initial response time average = C/2, completion time = 3C/2, throughput = 1/C Concurrency provides throughput advantage only if connection time is relatively long, C>>T. Concurrency may provide faster first responder time only if C>>T. Same for completion time. Concurrent is good if thread creation overhead is small, thread overlap is possible, program design is simplified.  Discuss design principles that can improve the robustness of server applications. Use standard functions, respond to exceptions properly, prevent buffer overflow, check compliance of incoming requests, resource management, provide session recovery, use log files, consider security threats, use time-outs, Client Design Techniques (lecture 9)Describe roles for concurrency in clients. Separates functionality into distinct components, can simultaneously contact multiple servers, allows interaction while a request is in process, increased performance for overlapping operations, provides asynchrony.  Discuss design principles that can improve the robustness of client applications. Use standard routines, catch exceptions, prevent buffer overflow, check compliance of replies from servers, resource management, session recovery, consider security risks, use time-outs Design Examples (lecture 10)Discuss the key features and differences between the different designs for the ECHO servers and clients. Iterative server – single thread, one client serviced at time Multithreaded server – generates threads on demand, 1 child thread per client, multiple clients concurrently Predetermined server – each child thread accepts and services connections, each client processed by only 1 child thread, multiple clients concurrently Asynchronous server – callback methods are invoked to complete accept, receive, and send. Each callback method executes in a different thread, multiple clients concurrently. Main starts accept, accept starts receive and another accept, read calls a send, sends calls another read FastCallback server – Receive starts both a send and another receive, send does not need to start another send, send sets a signal to let receive know when to proceed Apparent server – a “select” call is used to check multiple sockets for readiness of server, single thread, multiple clients concurrently

handler.Close(); } Asynchronous server: Main: listener.BeginAccept( new AsyncCallback(AcceptCallback), listener); Main does something else (or nothing) Accept: Socket handler = listener.EndAccept(ar); handler.BeginReceive(state.buffer,0,StateObject.BufferSize,SocketFlags.None,new AsyncCallback(ReadCallback), state); listener.BeginAccept(new AsyncCallback(AcceptCallback), listener); Read: int bytesRead = handler.EndReceive(ar); if (bytesRead > 0) { handler.BeginSend(state.buffer, 0, bytesRead, SocketFlags.None, new AsyncCallback(SendCallback), state); } else { handler.Shutdown(SocketShutdown.Both); handler.Close(); } Send: int bytesSent = handler.EndSend(ar); handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, SocketFlags.None, new AsyncCallback(ReadCallback), state); FastCallback Server: Read: int bytesRead = handler.EndReceive(ar); state.sendDone.WaitOne(); if (bytesRead > 0) { state.sendDone.Reset(); handler.BeginSend(state.buffer, 0, bytesRead, SocketFlags.None, new AsyncCallback(SendCallback), state); byte[] temp = state.buffer; state.buffer = new byte[StateObject.BufferSize]; handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, SocketFlags.None, new AsyncCallback(ReadCallback), state); } else { handler.Shutdown(SocketShutdown.Both);

handler.Close(); } Send: int bytesSent = handler.EndSend(ar); state.sendDone.Set(); Apparent server: ArrayList socketList = new ArrayList(); socketList.Add(listener); ArrayList tempList = new ArrayList(); while (true) { tempList.Clear(); for (int i=0; i 0) handler.Send(buffer, bytesReceived, SocketFlags.None); else { handler.Shutdown(SocketShutdown.Both); handler.Close(); socketList.Remove(tempList[i]); } Iterative client: sender.Connect(remoteEP); int bytesSent = sender.Send(msg); do { bytesRec = sender.Receive(bytes, bytes.Length, SocketFlags.None);

Uses TCP to reliably send email over port 25. Transfer is direct, from sending mail server (SMTP client) to receiving mail server (SMTP server). Handshake, transfer of messages, closing. Sender initiates transfer: HELO xx@sss, MAIL FROM: , RCPT TO: , DATA (CRLF, CRLF), QUIT  Describe the characteristics of mail message formats. Header (To:, From:, Subject: )and body (ASCII characters only)  Describe the role of MIME in email. Allows inclusion of non ASCII content in mail messages, must be converted to 7 bit ascii. Text (plain, html), Image (jpeg, gif), Audio (basic, 32kadpcm), Video (mpeg, quicktime)  Describe the basic operation of POP3 for mail access. Recipient initiates transfer, authentication phase, transaction phase, updates mail queue. Project 1 and 2Write pseudocode and/or C# code snippets for key functionality in the Project 1’s clients and servers and Project 2’s server