IK2218 Homework 3 Solutions 2019
IK2218 Homework 3 Solutions 2019
IK2218 Homework 3 Solutions 2019
Homework Assignment 3
Problems
The pseudo-code sample below (with most details omitted) describes an application that uses the
socket interface (API) for communication.
s = socket(…);
bind(s, …);
listen(s, …);
while true {
t = accept(s, …);
recv(t, …);
ProcessRequest(…);
send(t, …);
close(t);
}
a) Is the sample code for a client or a server? Does it use TCP or UDP? Explain your answer. (5 p)
b) The textbook gives two examples of communication using the socket interface: 1) connection-
oriented, concurrent communication and 2) connectionless, iterative communication.
Characterize the communication in the sample code using this terminology. (5 p)
c) In practice, this kind of communication is not frequently used. What is the main limitation?
(5 p)
Solution
a) The code is for a TCP server. It does not initiate the communication itself; instead, it waits to
be contacted. Hence, it is a server. Only a TCP server uses listen() and accept().
b) Connection-oriented, iterative communication.
c) The server can only deal with one client request at a time. (How severe that limitation would be
depends on the complexity of the request processing, represented by the ProcessRequest()
function.)
1
2. Web (35 p)
Suppose that you click on a link on a web page, which causes the following HTTP request to be
sent.
a) Which web document does the browser request? Answer by giving the URL. (3 p)
b) Which version of HTTP is the browser using? What kind of connection is requested, persistent
or non-persistent? (Note that the textbook does not cover header fields related to persistence,
so you may want to consult other resources, on the Internet for example.) (3 p)
more data…
2
Solution
a) http:/www.feathers.org/swordfish
b) HTTP version 1.1. The browser is requesting a persistent connection.
c) The server accepts a non-persistent connection.
d) 1) This response is a normal response when a page is moved. 2) The client is redirected to the
new location, as specified by the “Location” header, so the client should send another request
for the new object. 3) In this case, the client is redirected from a non-encrypted connection to
an encrypted connection, i.e., from a URL with “http:” to a URL with “https:”, so the server
has been configured to enforce encrypted communication.
e) The transaction involves fetching the main HTML object, and then the three objects it
contains.
1. 8×RTT. First one TCP SYN/ACK and one HTTP request/response for the main HTML
object. Then, for each contained object, one TCP SYN/ACK and one HTTP
request/response.
2. 4×RTT. First one TCP SYN/ACK plus one HTTP request/response for the main HTML
object. Then the contained objects are fetched in parallel, each with a TCP SYN/ACK and
an HTTP request/response.
3. 5×RTT . One TCP SYN/ACK and then one HTTP request/response for each object.
4. 3×RTT. First one TCP SYN/ACK plus one HTTP request/response for the main HTML
object. Then the client uses HTTP pipelining and sends requests for the contained objects
back-to-back, without waiting for responses in between. The responses are returned back-
to-back.
Grading suggestions: The main thing here is to demonstrate an understanding of how TCP
SYN/ACK and HTTP request/response are combined. In which order are they performed, and
what can be done in parallel? Incomplete or missing explanations render deduction in points.
3. Mail (25 p)
Consider the scenario when Alice (left) sends an email to Bob (right). There are two intermediate
systems: outgoing mail server and incoming mail server.
3
Solution
a) If the outgoing mail server is removed, Alice’s UA needs to contact the incoming mail server
directly in order to send the mail. The incoming mail server may not be able to receive the mail
– it could be busy or otherwise unavailable – and then Alice’s UA cannot send the mail, and has
to wait until the incoming mail server becomes available. Hence, the outgoing mail server
offloads Alice’s UA by queuing messages waiting to be sent.
(An outgoing mail server is also important for controlling the sending of mail from an
organization. It can control what clients are allowed to send mail as a way to prevent abuse,
spam for instance. This is not a required part of the solutions, though, so there is no reduction in points for
not mentioning this.)
b) The incoming mail server stores Bob’s mail, and Bob can access the mail whenever he wants. If
the server is removed, Bob has to be online in order to receive mail. (It also means that Bob
will store all mail on his computer, so he cannot access his mail from another computer. (No
reduction in points for not mentioning this.)
1: SMTP. 2: SMTP. 3: POP or IMAP (HTTP is also a valid answer, if the UA is web-based).
4. DNS (25 p)
You use the “dig” lookup tool to get the IP address of KTH’s web server “www.kth.se”. You want
to try different name servers, so you specify the DNS server as an argument to dig (the server’s IP
address prepended with ‘@’). You run the following three commands:
a) Explain the results: Describe the responses from the three DNS servers. What do the responses
say? We distinguish between four kinds of name servers: root, TLD, authoritative, and local.
You can deduce just from studying the responses what kind of DNS server it is (the flags are
useful here, among other things). For each of the three cases, describe the kind of name server
that is responding to your query. Explain what the response contains. Also, for each name
server, explain whether or not the answer contains the IP address you are looking for. You only
need to discuss the responses at a general level – you should not discuss or describe the details of the messages, the
different fields, their contents, etc. However, you probably need to study the responses carefully in order to be able
to explain them. (15 p)
b) Organizations often have multiple name servers for their domains. What is the purpose of
having multiple name servers? How are they kept synchronized? (5 p)
c) It is sometimes useful to have more than one name in DNS for the same computer. Is it
possible for a computer to have two names under different top-level domains? For example,
one name in the “com.” TLD and one in “se.”. If so, give an example when this might be
useful. (5 p)
Solution
DNS
a) The first response (192.36.135.107) is from a TLD server for the “se” top-level domain. The
response contains the (authoritative) name servers for “kth.se”. The second response is from a
root server, and gives the TLD servers for the “se” top-level domain. The last answer is from
an authoritative server for “kth.se”, and gives the IP address of the web server.
b) Having multiple name servers is for redundancy. When an organization has multiple name
servers, there is one primary server and several secondary servers. The zone file is updated on
4
the primary server, and then the updates are transferred automatically to the secondaries
through “zone transfers”.
c) It is perfectly legal to have names in different top-level domains. A web server for the
“feathers” company could have the names “www.feathers.com” and “www.feathers.se”. When
it gets a request to the name in the “se” domain, it responds with a page in Swedish, otherwise
in English. (Remember that an HTTP request contains the host name in the “Host:” header
field, so the server can examine the header to see what host name was used.)