T. Andrew Yang
|
Last updated: 10/3: Lab 3 revised 10/2/2024: Lab 3 posted 9/24/2024: Lab 2 posted 08/22/2024: Lab 1 posted |
NOTE: When preparing your
answers, you are welcome to use any resources, including the text books and the
class notes. However, make sure you properly cite the work of other
researchers or professionals. Visit https://sceweb.uhcl.edu/yang/citing.htm for more information about cited references.
Warning: Missing or improper cited references in your answers
will result in poor scores.
Note: You may cite the lectures if your answer comes from the lectures.
Note about AI tools: You
may use AI tools such as ChatGPT as a starting point while putting together
your own answer; however, simply copying the answer produced by ChatGPT (or
any AI tool) is considered cheating.
Total: 100 points
Go to
the Index
Total:
100 points
Layer 2 header:
Source =
Destination =
|
IP header:
Source IP =
Destination IP =
|
TCP header:
Source IP =
Source port =
Destination IP =
Destination port =
|
HTTP packet:
GET ...
...
|
Go to
the Index
Total:
100 points
-
Python files to be used in this lab: serverTCP5.py clientTCP5.py testData5.txt (revised)
-
Screen shots of running this pair of server
and client programs using the provided test data file:
|
|
1.
(5
pts) First, run the provided client and server programs using the
provided test data file.
To
hand in: The screenshots of running the programs on a computer.
2.
(5
pts) Run the client and the server programs on two separate computers
connected to the same local area networks. In the client program, use the
server computer’s IP address as the value of serverName (line #13). Run the
revised programs.
To
hand in: The screenshots of running the programs on a computer.
3. Revise
the client program that you used in EX 2 above by measuring the ‘send time’ and
the ‘receive time’. NOTE: The sum of ‘send time’ and ‘receive time’ is the
Round Trip Time (RTT). Add statements within and outside the loop to
calculate the average ‘Disk Access Time (DAT)’, the average ‘Send Time (ST)’,
the average ‘Receive Time (RT)’, and the average ‘Round Trip Time (RTT)’.
The
output screen generated by the revised client program should look similar to
Figure 1.
Server screen output: |
Client screen output: C:\sockets>python
clienttcp7.py experiment 0
---------------------------------------------- Reading data from file 34191 bytes read from
the file >>>>>
elapsed time of file read: 0.000000 >>>>>>>>>>>>>>>>>>>>
send time = 0.000000 >>>>>>>>>>>>>>>>>>>>
34191 bytes sent to the server. >>>>>>>>>>>>>>>>>>>>
receive time = 0.000000 >>>>>>>>>>>>>>>>>>>>
34191 bytes received from the server. >>>>>
round trip time (RTT) = 0.000000 experiment 1
---------------------------------------------- Reading data from file 34191 bytes read from
the file >>>>>
elapsed time of file read: 0.000000 >>>>>>>>>>>>>>>>>>>>
send time = 0.000000 >>>>>>>>>>>>>>>>>>>>
34191 bytes sent to the server. >>>>>>>>>>>>>>>>>>>>
receive time = 0.000000 >>>>>>>>>>>>>>>>>>>>
34191 bytes received from the server. >>>>>
round trip time (RTT) = 0.000000 experiment 2
---------------------------------------------- Reading data from file 34191 bytes read from the
file >>>>>
elapsed time of file read: 0.000000 >>>>>>>>>>>>>>>>>>>>
send time = 0.000000 >>>>>>>>>>>>>>>>>>>>
34191 bytes sent to the server. >>>>>>>>>>>>>>>>>>>>
receive time = 0.000000 >>>>>>>>>>>>>>>>>>>>
34191 bytes received from the server. >>>>>
round trip time (RTT) = 0.000000 experiment 3
---------------------------------------------- Reading data from file 34191 bytes read from
the file >>>>>
elapsed time of file read: 0.015595 >>>>>>>>>>>>>>>>>>>>
send time = 0.000000 >>>>>>>>>>>>>>>>>>>>
34191 bytes sent to the server. >>>>>>>>>>>>>>>>>>>>
receive time = 0.000000 >>>>>>>>>>>>>>>>>>>>
34191 bytes received from the server. >>>>>
round trip time (RTT) = 0.000000 experiment 4
---------------------------------------------- Reading data from file 34191 bytes read from
the file >>>>>
elapsed time of file read: 0.000000 >>>>>>>>>>>>>>>>>>>>
send time = 0.000000 >>>>>>>>>>>>>>>>>>>>
34191 bytes sent to the server. >>>>>>>>>>>>>>>>>>>>
receive time = 0.000000 >>>>>>>>>>>>>>>>>>>>
34191 bytes received from the server. >>>>>
round trip time (RTT) = 0.000000 average DAT = 0.003899. average ST = 0.000000. average RT = 0.000000. average RTT = 0.000000. C:\sockets> |
Figure 1. Screen output of the revised client program
(showing the ‘send time’ and ‘receive time’ separately).
To
hand in:
3.1.
(25
pts) The revised client program.
3.2.
(5
pts) The screenshots of running the programs on a computer.
3.3.
(5
pts) The screenshots of running the programs on two different
computers.
3.4.
(10
pts) Explain the discrepancy between the 'send time' and the 'receive
time'. That is, why is the 'send time' always zero (even when the client and
the server programs are on two different computers)? Hint: Review 'Using a
Socket' at https://docs.python.org/3/howto/sockets.html.
4.
As you may have noticed in the above exercise,
without proper acknowledgments between the client and the server, the ‘send
time’ measured by the client program is always zero.
Revise
the method of measuring the 'send time' by waiting until an acknowledgement is
sent from the server and received by the client to start measuring the 'send
time'.
Similarly,
revise the programs such that a more accurate calculation of the 'receive time'
is implemented. That is, once the server sends an ACK to the client, it waits
for the client to send back another ACK before it starts to send the data back
to the client.
NOTE:
To implement the acknowledgement mechanism, both the client and the server
program must be revised.
A
sample screen output that would be generated by the revised programs is shown
in Figure 2.
Server output screen: |
Client output screen: C:\sockets>python
clienttcp9localserver.py experiment 0
---------------------------------------------- Reading data from file 46513 bytes read from
the file >>>>>
elapsed time of file read: 0.000495 Waiting to receive ACK
from server ... ACK: from server:
46513 bytes received. Sending an ACK back to
server ... >>>>>>>>>>>>>>>>>>>>
send time = 0.000501: 46513 bytes sent
to the server. >>>>>>>>>>>>>>>>>>>>
receive time = 0.000499: 46513 bytes
received from the server. >>>>>
round trip time (RTT) = 0.001503 experiment 1
---------------------------------------------- Reading data from file 46513 bytes read from
the file >>>>>
elapsed time of file read: 0.000502 Waiting to receive ACK
from server ... ACK: from server:
46513 bytes received. Sending an ACK back to
server ... >>>>>>>>>>>>>>>>>>>>
send time = 0.000501: 46513 bytes sent
to the server. >>>>>>>>>>>>>>>>>>>>
receive time = 0.001003: 46513 bytes
received from the server. >>>>>
round trip time (RTT) = 0.002005 experiment 2
---------------------------------------------- Reading data from file 46513 bytes read from
the file >>>>>
elapsed time of file read: 0.000501 Waiting to receive ACK
from server ... ACK: from server:
46513 bytes received. Sending an ACK back to
server ... >>>>>>>>>>>>>>>>>>>>
send time = 0.002006: 46513 bytes sent
to the server. >>>>>>>>>>>>>>>>>>>>
receive time = 0.001004: 46513 bytes
received from the server. >>>>>
round trip time (RTT) = 0.003511 experiment 3
---------------------------------------------- Reading data from file 46513 bytes read from
the file >>>>>
elapsed time of file read: 0.000502 Waiting to receive ACK
from server ... ACK: from server:
46513 bytes received. Sending an ACK back to
server ... >>>>>>>>>>>>>>>>>>>>
send time = 0.001003: 46513 bytes sent
to the server. >>>>>>>>>>>>>>>>>>>>
receive time = 0.000483: 46513 bytes
received from the server. >>>>>
round trip time (RTT) = 0.002505 experiment 4
---------------------------------------------- Reading data from file 46513 bytes read from
the file >>>>>
elapsed time of file read: 0.000501 Waiting to receive ACK
from server ... ACK: from server:
46513 bytes received. Sending an ACK back to
server ... >>>>>>>>>>>>>>>>>>>>
send time = 0.003508: 46513 bytes sent
to the server. >>>>>>>>>>>>>>>>>>>>
receive time = 0.001004: 46513 bytes
received from the server. >>>>>
round trip time (RTT) = 0.005013 average DAT = 0.000625. average ST = 0.001880. average RT = 0.000998. average RTT = 0.003634. C:\sockets> |
Figure 2. Screen output of the revised client
and server programs (showing the two ACKs)
To hand in:
4.1. (35 pts) The revised programs.
4.2. (5 pts) The screenshots of
running the programs on a computer.
4.3. (5 pts) The screenshots of
running the programs on two different computers.
5. (Bonus project, optional) What
would happen if the data sent from the client is larger than the size of the
buffer used by the server? What will happen is that the server will only read as
many bytes as its buffer size. To witness this problem, reduce the size of the
buffer in the server to, say 2048, and see the data loss in action. Read the
discussion related to this issue at this page (https://docs.python.org/3/howto/sockets.html#using-a-socket,
under 'Using a Socket') to find possible solutions to mitigate the problem.
To do:
(a)
A solution is to have the client, before sending
the actual data, first send the number of bytes of the data.
Hint: The size of the data, an int, must be
converted to bytes (of hexadecimal values) in order to be sent over the socket.
Hint: Use the to_bytes() function. See an example on https://www.geeksforgeeks.org/how-to-convert-int-to-bytes-in-python/.
When the bytes are received by the server, they must be converted back to int.
Hint: Use the from_bytes() function. See https://www.geeksforgeeks.org/how-to-convert-bytes-to-int-in-python/.
(b)
Once the server has received the number of bytes
of the data, the server then goes into a loop to read the data, one chunk per
iteration, until the size of all the read chunks is the same as the size of the
data it expects to receive. Hint: The size of the chunk is the same as the
buffer size, except for the last chunk, which is less than the size of the
buffer used by the server.
Sample
screen outputs from the client (left) and the server (right) are shown in
Figure 3.
Partial
screen output generated by the server: |
Screen output by the client: |
Figure 3. Screen outputs respectively generated
by the client and the server programs.
To hand in:
5.1. (35 pts) The revised programs.
5.2. (5 pts) The screenshots of
running the programs on a computer.
Go to
the Index