Contents
1 Lab Overview 4
2 Setup 4
3 Assignments 4
3.1 Mandatory Assignment: Chat Client (0-150 points) . . . . . . . . . . . . . . . 6
3.2 Mandatory Assignment: TCP Trace Analysis (0-100 points) . . . . . . . . . . 8
3.3 Chat Server (250 points) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.4 Chat Client for Unreliable Networks (500 points) . . . . . . . . . . . . . . . . . . 11
3.5 Packet Analysis (500) points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.5.1 HTTP Trace Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.5.2 Botnet Reverse-Engineering . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.6 DIY DNS Server (750 points) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.7 Online-Multiplayer Game (1000 points) . . . . . . . . . . . . . . . . . . . . . . . 19
A Chat Application Protocol 20
B Socket Interface Reference 21
C Threading Interface Reference 23
D Commands to Configure the Unreliable Chat Server 24
3
1 Lab Overview
Part of becoming a Computer Scientist is equipping yourself with the practical skills you will
need to solve real-world problems, and computer programming is one of these skills. In this lab,
you learn how to build networked applications and write programs that use sockets. This guide
describes all available lab assignments. Completing a lab assignment earns you points for the
course. Every assignment lists the number of points it is worth in its title.
There are two mandatory lab assignments. In the first one, you will implement a simple chat
application. You can find the description for this assignment in Section 3.1, and a full description
of the chat protocol in Appendix A. The second mandatory assignment involves visualizing and
reading network traces with Wireshark. Here, you will analyze the trac between your chat
client (from the previous mandatory assignment) and our server.
After you complete these assignments, you should be able to create your own simple networked
applications using sockets and TCP/IP.
! You must pass the mandatory assignments to pass the course.
2 Setup
This section helps you set up the tools you will need to complete the lab assignments. If you run
into problems installing the required software, you can use the virtual machine (VM) provided
on Canvas. The VM comes with the required software preinstalled.
The assignments are to be completed using the Python 3 programming language. Please
download and install Python 3 via its website1 or your package manager. Once you have Python
installed, you can test that it works by typing python on the command line (Unix, MacOS), or
opening the IDLE Python interpreter (Windows).
Once you have Python 3 installed, you may want to install a text editor or integrated development environment (IDE). We recommend Visual Studio Code,2 but many other good editors
exist for Python.
Python is an interpreted language, which means you do not need to compile your program
to machine instructions before running it. You can run your code directly from your IDE, or by
passing it as an argument to Python by running “python3 path-to-python-script.py.”
3 Assignments
This section describes the Computer Networks lab assignments. The first two assignments are
mandatory, and must be completed to pass the course. The other assignments are optional.
Completing assignments earns you points. Every assignment lists its reward in the title. Some
assignments have a variable reward. Read their description for more details.
Each assignment must be approved by a TA during a lab session, and handed in on Canvas.
The deadline for the assignments can be found on Canvas and in the course syllabus. The TAs
are present during the lab sessions to provide support for the mandatory assignment. You are
expected to complete the other assignment without external help, but TAs are there to provide
support in extreme cases.
1https://www.python.org/
2https://code.visualstudio.com/
4
! Your code must directly use Python’s socket library. The use of other libraries for
network-related functionality (e.g., socketserver, zlib) is not permitted.
! Using the socket.sendall method is not allowed. Use socket.send instead.
5
3.1 Mandatory Assignment: Chat Client (0-150 points)
In this assignment, you implement a text-based chat client. For this, you use Python, sockets, and
the Transmission Control Protocol (TCP). Once you are comfortable using the socket interface,
using sockets in other programming languages should be straightforward.3 After completing this
assignment, you will be able to exchange messages with your fellow students using your own
client.
The chat client and chat server are built on top of TCP and use their own application-layer
protocol. This means the client and server can request the other to perform actions by sending
predefined types of messages. For example, your client can ask the server to forward a message
to another user’s client by sending the string “SEND username insert your message here\n”
to the server, where “username” is the user to whom you want to send your message. If your
message is correct, the server will send two messages: one to the destination user, forwarding
your message, and one back to you that says “SEND-OK\n”, to notify you that your message was
forwarded successfully.4 Keep in mind that these messages can be of any length. Therefore, you
need to make sure that your client can handle arbitrary message lengths. The full details of the
protocol are listed in Appendix A.
Similar to Web browsers and other modern applications, your chat client does not expose the
protocol it uses to the user. Instead, it provides a user-friendly text-based interface that makes it
easy for users to chat with others without knowing the protocol specifications. The specifications
of this interface, and the requirements of this assignment, are listed below.
Requirements
Your application must:
1. Implement the chat protocol described in Appendix A.
2. Connect to the chat server and let the user log in using a unique name.
3. Ask for another name if the chosen name is already taken.
4. Let the user shutdown the client by typing !quit.
5. Let the user list all currently logged-in users by typing !who.
6. Let the user send messages to other users by typing @username message.
7. Receive messages from other users and display them to the user.
The chat server is hosted by the teaching team. Its address can be found on Canvas. For
testing purposes, a special user called echobot is always online. Echobot is a chatbot that replies
to all your messages by sending back the same message it receives.
Evaluation
A teaching assistant will ask you questions about your code and check its correctness. The reward
for this exercise is based on the Canvas submission date and time of your approved assignment.
150 points Submit the assignment during your lab in week 1 or 2.
100 points Submit the assignment during your lab in week 3.
50 points Submit the assignment during your lab in week 4.
3Famous last words.
4Make sure that you receive this OK before asking the user for the next message to send.
6
Resources
You can find the full protocol used by the server and clients in Appendix A. References for
programming with sockets and threads can be found in Appendices B and C respectively.
7
3.2 Mandatory Assignment: TCP Trace Analysis (0-100 points)
In this assignment, you will use your chat client to track and trace your connection with the
server and observe the intricacies of the TCP connection. Because TCP is designed to be reliable,
it has several mechanisms to keep track of in-order packet delivery and guaranteed delivery. We
want you to explore these features hands-on by taking a look at how the chat client communicates
with the server using this transport layer protocol. To this end, you will run your chat client
and analyze the TCP trac using Wireshark, a packet analysis tool. Capture the trac between
your client and the server and answer the questions.
Requirements
Successfully complete the steps below. First, perform these steps by yourself. Once you are
comfortable with answering all questions, ask a TA to sign o↵ your assignment and repeat the
process.
1. Use Wireshark to capture trac between your chat client and the server when sending
several chat messages.
2. Answer and discuss the following questions (with a TA):
(a) Which segments perform the TCP connection handshake between client and server?
How can you tell?
(b) What are the initial (absolute) sequence numbers of the client and server? Is this
expected behavior? Why?
(c) Which bytes in the TCP segments represent the chat message data? How can you
find out?
(d) Which flags are used in segments that carry chat messages?
(e) Where in the trace are the segments that carry chat messages acknowledged by the
TCP protocol? Where are they acknowledged by the application?
(f) How do the sequence and acknowledgment numbers change during the trace? Is this
expected?
(g) Which segments close the TCP connection? How can you tell?
3. When signing o↵ your assignment with a TA:
(a) Save the questions and your answers in a text or PDF file.
(b) Save your Wireshark trace.
(c) Upload your written answers to your questions to CodeGrade.
Evaluation
A teaching assistant (TA) will approve your assignment if you correctly complete the requirements
above. Upload the questions and your answers, in a text or PDF file, to Canvas. Please clearly
state your answers to each question. The TA may ask additional questions to evaluate your
understanding. Make sure you are ready to show your findings by having Wireshark open and
your chat client ready to run. The reward for this exercise is based on the Canvas submission
date and time of your approved assignment.
100 points Submit the assignment before or during your lab in week 6.
50 points Submit the assignment during your lab in week 7.
8
Resources
Wireshark Download and install Wireshark from http://www.wireshark.org/download.html.
Get familiar with its basic workings. Try capturing packets from an interface by navigating to the “Capture” menu and choosing “Interfaces”. Click “Start” to begin capturing
packets. Make sure there is some network activity so that there are packets for Wireshark
to capture. Click “Stop” in the “Capture” menu to stop capturing packets. You should
see several lines of captured packets. Click some of the packets and examine them. Use
“Filter” to see focused output. Once you are familiar with the basic workings of Wireshark,
move on to the assignment.
9
3.3 Chat Server (250 points)
In the chat client assignment, you used a server hosted by the teaching team. This server connects
multiple clients and forwards messages between them. In this assignment, you implement your
own chat server using the same protocol.
Unlike the client, the server is likely to have multiple open connections at the same time—one
for each client that is connected to it. Because it is impossible to predict when a client will send
a request or message, your server needs to keep checking all connections for incoming data. Both
polling and multi-threading are allowed as solutions to this problem.
Requirements
1. Support the full protocol specified in Appendix A.
2. Support at least 64 simultaneous clients.
Evaluation
The TAs will ask you questions about your code and check its correctness, possibly by chatting
with each other using your server.
Resources
See the resources listed in Section 3.1.
10
3.4 Chat Client for Unreliable Networks (500 points)
In the mandatory assignment, you implemented a simple chat client. Because the interfaces
and protocols of computer networking are already well-established, there are many challenges
that you do not need to take into account. For example, once a connection is established, TCP
provides a stream of bytes in the order they were sent and without error. This assignment
asks you to give up such conveniences and instead provide solutions to some of these challenges
yourself.
Assignment Description
The Internet Protocol (IP) is an unreliable datagram protocol. Fortunately for many application
programmers, the Transport Control Protocol (TCP) runs on the hosts and hides the unreliability
of the network and underlying protocols.
Implement a chat client that uses UDP and the protocol shown in Appendix A. This chat
client must be able to communicate with similar clients via the Unreliable Chat Server, whose
address can be found on Canvas. You can configure the Unreliable Chat Server to simulate
an unreliable network by letting it drop a fraction of the received messages, insert errors into
messages, or even change their order. Use this to test the correctness of your chat client. The
commands used to configure the server are listed in Appendix D.
Your chat client should meet all the requirements listed in Section 3.1, as well as the requirements below.
Requirements
1. Use UDP instead of TCP.
2. Guarantee delivery of messages using acknowledgments.
3. Protect against errors in the message. The client must detect at least single, double, and
triple-bit errors.
4. Messages are delivered in the order they are sent.
5. The interface shown to the user does not di↵er from the one in the mandatory assignment.
Assessment
Show that your chat client hides the unreliability of the network from the user. Configure the
Unreliable Chat Server and send messages between two instances of your client.
11
3.5 Packet Analysis (500) points
! The assignments in this section are mutually exclusive. You can get points for one
or the other, but not for both.
3.5.1 HTTP Trace Analysis
! If you complete this exercise, you cannot complete the exercise in Section 3.5.2.
In this assignment, you will capture and analyze a network trace between your browser and
a Web server. Web servers and proxies are one of the most widely-deployed server applications,
powering the websites that we visit every day. The protocol behind the Web, the HyperText
Transfer Protocol (HTTP) started out as a simple plain-text protocol built on top of TCP. The
most widely-used plain-text version of the protocol is HTTP/1.1.5
As the Web evolved, the number of protocol extensions kept increasing, and the size of
websites, or “Web applications”, increased together with the number of users. Improving HTTP
performance and combining extensions into one standard, HTTP/26 came out many years later.
Three important improvements introduced in HTTP/2 are:
1. Multiplexing. HTTP/2 is a multiplexed protocol: multiple requests can be made at the
same time, and multiple responses can be received in one message.
2. Header compression. During a web browsing session, the headers your browser will send to
the server will remain more or less the same, and the headers the server will send to your
browser will also not change by much. To spare bandwidth, headers are compressed and
are sent less often, as you will see in the traces.
3. The most apparent one: HTTP/2 is a binary protocol. This makes it much more dicult
to manually read and write HTTP messages.
Although a newer version of HTTP, called HTTP/3 exists,7 we focus in this assignment on
HTTP/2. The most important change from HTTP/2 is that HTTP/3 uses UDP, not TCP,
for its transport layer protocol, and moves the responsibility for managing connections and
reliable delivery from the transport layer to the application layer. For further reading on how
HTTP/3 implements these changes, see QUIC.8 To obtain an overview of the HTTP protocol
versions and their implementations, we recommend reading the articles available at https:
//developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP.
Assignment Description
You are going to interact with a Web server that is both HTTP/1.1- and HTTP/2-enabled,
and see how HTTP requests and responses look in practice. First, you are going to take a look
at HTTP/1.1, and then at HTTP/2.
5You can find the newest HTTP/1.1 standard at https://datatracker.ietf.org/doc/html/rfc9112 6The newest HTTP/2 standard: https://datatracker.ietf.org/doc/html/rfc9113 7The HTTP/3 standard: https://datatracker.ietf.org/doc/html/rfc9114. Observe how the RFC numbers
are consecutive! 8QUIC: https://www.chromium.org/quic/
12
Web browsers only support HTTP/2 when served using Transport Level Security (TLS) (you
will see the URL starts with https://). Although Wireshark intercepts all packets between your
system and the Web server, TLS prevents us from reading the contents of the packets because
it is designed to be resistant against Man-In-The-Middle Attacks (MITMs). This means we will
need to do a bit of setup9 to enable Wireshark to decrypt the data, i.e., the HTTP/2 messages.
This is an example of protocol encapsulation: HTTP/2 messages are encapsulated in TLS!
Setup
1. Download the support script from Canvas: mosaic support.cmd for Windows, and
mosaic support.sh for Linux and macOS.
By default, the scripts try to launch Google Chrome. If you prefer a di↵erent browser,
please modify the script accordingly.
2. (For Mac and Linux only) Make the script executable by running at the command line
chmod +x mosaic support.sh.
10
3. Close all instances of Chrome (or what browser you modified the script to run). End the
task from Task Manager, run pkill chrome on Linux and Mac.
4. Run the script. A browser window should appear.
5. Open Wireshark, and select your active network interface (you can judge which one it is by
the activity graph next to its name). Then go to Edit (in the menu bar) ! Preferences !
Protocols ! TLS. Press the “Browse” button next to “(Pre)-Master-Secret log filename”,
and select the file named keylogfile.txt in your home directory.
! Making sense of packet traces in Wireshark without using filters can be very di-
cult. You can write http in the filter box and only HTTP/1.1 traces will be shown.
For HTTP/2, you can use http2. There are many other filters, for example for
filtering based on the host and/or port. Try them out and discover!
Requirements
Consider server url to mean the URL of the assignment server, which can be found on
Canvas.
Set up according to the instructions above and answer the questions below. When you are
confident you have correctly answered all questions, discuss your trace and answers with a TA to
get your assignment signed o↵. You do not need to redo the trace when discussing your answers
with the TA.
1. Navigate to http://server url:8080. Press on the links, and familiarize yourself with
how the website looks. Look on the Wireshark trace, identify the packets that go from the
client to the server, and the ones that go from the server to the client.
9That is, Putting-yourself-In-The-Middle. 10Read “CHange MODe to set the eXecutable bit.”
13
" You will get a certificate error from your web browser, warning you that
the connection is not safe. For a real website, this would be a problem,
but this is completely fine for our assignment. You can ignore the error by
pressing “Advanced” and then clicking the link at the bottom (“Proceed to
server name (unsafe)”
2. Click on “Click for HTTP request information”. You will see the HTTP headers that the
server received from your browser. Now look in Wireshark. Are the HTTP headers that
the browser sends to the server the same as the ones on the screen? If there are di↵erences,
what are they?
3. What do the headers mean?
4. Reload the page, first by pressing F5, then by pressing Ctrl+F5. Are the headers di↵erent
if you press CTRL when refreshing? Why? What do the changed headers mean?
5. Navigate to http://server url:8080/gophertiles. You will see a picture11 made of
smaller tiles loading. Can you find the request and response for each of the tiles in Wireshark? How does the server know which tile to serve? You may observe that your browser
uses more than one TCP connection to load the pictures. Why is this happening? How can
you find in Wireshark how many TCP connections are used by your browser, and which
connection is used for every tile? How many connections are used?
6. (HTTP/2, dicult) Navigate to https://server url:4430. What does this request look
like in Wireshark? Are the headers and the page’s content separated? How does the
decrypted response di↵er compared to the HTTP/1.1 version?
7. (HTTP/2, dicult) Navigate to https://server url:4430/gophertiles. Once again,
an image made of tiles is shown, but it loads much faster. As you select higher latencies
from the top-left corner, no matter what you select, the HTTP/2-enabled page loads much
faster. Why is this the case? What do the client’s requests for the tiles look like, and what
is the di↵erence compared to the HTTP/1.1 version? What do the server’s responses look
like? How many TCP connections does the browser use to load the tiles in the HTTP/2
version, and why is it the case?
8. (HTTP/2 and TLS, dicult) As HTTP/1.1 and HTTP/2 look completely di↵erent on
the wire, there needs to be a way for the server and client to communicate which version
to use, in a backwards-compatible way. This is done through Application-Layer Protocol
Negotiation, encoded as a TLS extension. Identify the negotiation in the Wireshark trace.
To force HTTP/1, you can use curl:
curl --insecure -v --http1.1 https://server name:4430/12
Similarly, for HTTP/2:
curl --insecure -v --http2 https://server name:4430
Evaluation
A teaching assistant (TA) will approve your assignment if you correctly complete the requirements
above. Upload the questions and your answers, in a text or PDF file, to Canvas. Please clearly
11Pictured is a UNIX system. 12We need the --insecure flag to ignore certificate errors.
14
state your answers to each question. The TA may ask additional questions to evaluate your
understanding. Make sure you are ready to show your findings by having Wireshark and your
network trace open.
3.5.2 Botnet Reverse-Engineering
! If you complete this exercise, you cannot complete the exercise in Section 3.5.1.
A botnet is a network of malware-infected computers. The malware makes the computer respond to remote commands send by an attacker. This attacker could, for example, instruct these
computers to all at once request a resource-intensive service from a single provider, executing a
Distributed Denial of Service Attack (DDoS).
Assignment Description
For clarity, we introduce two new terms. Firstly, we use “botnet executable” for the malicious
code that is running on an infected computer. Secondly, we use “botnet control server” for the
machine that sends malicious commands to these computers.
In this assignment, we give you a botnet executable. It is your task to reverse engineer the
protocol this executable uses to communicate with the botnet control server. Fortunately, this
particular botnet was made by us, and is not malicious, so you can safely run it on your machine.
Your task is to run the botnet executable, capture its trac while it is connected to the server,
and then analyze the captured trac to figure out how the botnet protocol works. This is a
common task for real-world malware analysts.
Requirements
1. Capture network trac from the botnet executable.
2. Reverse engineer the protocol used.
3. Answer the following questions about the botnet in your report:
(a) Which IP address and port number are used by the command server?
(b) What transport layer protocol is used by the botnet?
(c) What is the version number of the given bot client?
(d) The botnet supports 4 di↵erent commands (excluding the hidden command, which
you don’t need to describe here). What are they?
(e) (dicult puzzle) The protocol includes a single encrypted message type, which is sent
to the server after a certain kind of command is received. You may have to run the
bot multiple times to see the encrypted message. Try to find out how this message
is encrypted, and then decrypt it. Which encryption algorithm is used, and what is
used as the key? Please report to us a single decrypted message (copied verbatim,
including the checksum field), and the key that you used to decrypt it. Briefly describe
the structure of the message, and how you went about cracking the encryption.
(f) (dicult puzzle, optional) The protocol also includes a special kind of command which
contains a hidden message. This message is sent to the bot by the server after a
COMMAND request. You may have to run the bot multiple times to see the message.
15
The message includes a mysterious payload in which the server has hidden secret data
(hint: the secret data is in plaintext). What does this payload represent, and how is
the data hidden within it? Please describe how you figured this out. Also send us the
hidden data (plaintext) which you recovered from the payload.
Evaluation
The TA will first ask you to run the original executable, capture its network trac, and explain
the messages that are exchanged. Afterwards, the TA will discuss the answers you provided to
the questions listed in the requirements.
Resources
Botnet executable Download the executable from Canvas. We provide both a Windows (32-
bit/64-bit) and an Ubuntu Linux (32-bit/64-bit) binary. Choose the one that matches your
platform. If there is no binary matching your platform, you can run the 64-bit Ubuntu
Linux executable using the Virtual Machine provided on Canvas.
Wireshark Download and install Wireshark from http://www.wireshark.org/download.html.
Get familiar with its basic workings. Try capturing packets from an interface by navigating to the “Capture” menu and choosing “Interfaces”. Click “Start” to begin capturing
packets. Make sure there is some network activity so that there are packets for Wireshark
to capture. Click “Stop” in the “Capture” menu to stop capturing packets. You should
see several lines of captured packets. Click some of the packets and examine them. Once
you are familiar with the basic workings of Wireshark, move on to the assignment.
16
3.6 DIY DNS Server (750 points)
How many web pages do you visit in a day? Would you be able to remember all their IP addresses?
Probably not. It turns out that humans are bad at remembering arbitrary sequences of numbers,
but reasonably good at remembering names. By assigning names to IP addresses, web browsing
becomes doable for humans. Instead of having to remember the sequence “216.58.211.110,” you
only need to remember “www.google.com.” Your browser automatically translates this into the
correct IP address.13
However, this automated translation increases the complexity of the system, which now needs
to translate a name into an IP address before it can establish a connection. It would be infeasible
for every computer to keep a local, up-to-date copy, of all name-to-address mappings. Instead,
computers depend on a globally distributed system called the Domain Name System (DNS) to
look up these mappings dynamically.
This system contains a large hierarchy of servers called DNS servers. A DNS server is a
computer that keeps track of IP addresses and their associated domain names. DNS servers can
ask each other for the IP address matching a certain domain name. It then resolves, or translates,
this name into an IP address by looking it up in its local database, or by contacting other DNS
servers higher up in the hierarchy.
Assignment Description
DNS servers communicate with each other using their own protocol. It is your job to implement
your own DNS server that adheres to this protocol and performs recursive queries. Start by
reading the ocial specification, RFC 1035.14 The RFC mentions in detail the request formats,
the queries that you will receive, and more valuable information.
Requirements
Typically, a client application forwards a domain name to the operating system, which in turn
forwards it to a DNS server that performs recursive queries. Performing a recursive query means
that the DNS server will query other DNS servers until it finds the address that belongs to the
given domain name. This address is then returned to the application via the operating system.
Your task is to implement your own DNS server with the following requirements:
1. Perform recursive DNS queries.
2. Handle requests from multiple operating systems.
3. Implement the RTT (Round Trip Time) algorithm to choose a name server.
4. Implement the caching policy specified in the RFC section “7.4. Using the cache”
5. Handles mail exchange server requests.
13Another, more compelling, reason not to use IP addresses to identify Web pages is that it makes the assumption
a Web page is tied to a single machine, or network device. More generally, it creates a dependency between an
entity on one layer, and the implementation of a lower layer. Naming entities on their own layer solves this
problem, but the Domain Name System (DNS) does not do this. Instead, it translates a human-readable domain
name into an Internet address. I.e., it simply provides global, mutable, and easy-to-remember aliases for network
devices. The Web browser has to guess the right transport-layer address (port number) to find the right entity.
This system works because it relies on hard-coded port numbers. If you want to run your Web server on a di↵erent
port number, users have to enter it in their browser manually. This shows that, although we have DNS, there
is still a dependency between implementations across layers. This is not so much a shortcoming of DNS, as a
shortcoming of the design of the upper layers of the Internet. 14See https://www.ietf.org/rfc/rfc1035.txt.
17
Evaluation
Your implementation is evaluated by the TAs. To test your server implementation, you can
configure your Web browser or operating system to use it as its DNS server. Make sure that
your server can handle requests from di↵erent operating systems. Your implementation must
resolve requests by communicating with the root server and the servers it lists in its replies. You
cannot pass the assignment if you simply forward requests to another DNS server that performs
recursive queries.
Resources
Below is a list of free, popular, and public DNS servers. You can analyze their responses to learn
more about how to implement your own server.
Google (8.8.8.8 and 8.8.4.4)
Quad9 (9.9.9.9 and 149.112.112.112)
OpenDNS (208.67.222.222 and 208.67.220.220)
You can find the addresses of the DNS root servers at https://www.iana.org/domains/root/
servers.
18
3.7 Online-Multiplayer Game (1000 points)
Online games can be highly demanding on computer networks. They require both high bandwidth
and low-latency communication, often between large groups of players.
Assignment Description
In this assignment, you design, implement, and demo your own online-multiplayer game. To
participate in this assignment, you first need to write a plan for your game and get it approved.
Your plan must at least contain the following three parts:
1. A description of the game itself, and how it is played.
2. A design of your game, including its networking requirements. To get your plan approved,
you must show that these requirements pose sucient networking challenges. Examples of
suciently challenging designs are:
(a) Design a (real-time strategy) game that uses lock-step simulation15 and UDP.
(b) Design a high-paced shooter game that uses dead-reckoning and UDP.
(c) Design a game where one of the clients functions as the server, but can recover if this
client/server fails.
We also appreciate advanced and new ideas. Do not be afraid to be creative!
3. A description of your approach, and how this will meet your requirements.
Discuss your plan with the teacher before getting started. Plans are only approved if their
requirements are suciently complex. If you plan to complete this assignment, submit your game
plan several weeks before the assignment deadline and assume that your plan will require several
rounds of feedback before it is approved. If your plan is not approved, you cannot complete this
assignment.
Requirements
1. Submit your plan on Canvas.
2. Your plan must be approved by the teacher.
3. Build your game such that it meets the agreed-upon requirements.
Evaluation
Demo your game to, or play your game with(!), the TA. Show the TA the source code and explain
how your game works, how your game meets its requirements, and how you solved challenges
encountered along the way.
15See https://www.gamedeveloper.com/programming/1500-archers-on-a-28-8-network-programming-inage-of-empires-and-beyond.
19
A Chat Application Protocol
Message Sent by Description
HELLO-FROM <name>\n Client First hand-shake message.
HELLO <name>\n Server Second hand-shake message.
LIST\n Client Request for all currently logged-in users.
LIST-OK <name1>,..,<namen>\n Server A list containing all currently logged-in users.
SEND <user> <msg>\n Client A chat message for a user. Note that the
message cannot contain the newline character,
because it is used as the message delimiter.
SEND-OK\n Server Response to a client if their ‘SEND’ message
is processed successfully.
BAD-DEST-USER\n Server Sent in response to a SEND message to
indicate that the destination user is not
currently logged in.
DELIVERY <user> <msg>\n Server A chat message from a user.
IN-USE\n Server Sent during handshake if the user cannot log
in because the chosen username is already in
use.
BUSY\n Server Sent during handshake if the user cannot log
in because the maximum number of clients
has been reached.
BAD-RQST-HDR\n Server Sent if the last message received from the
client contains an error in the header.
BAD-RQST-BODY\n Server sent if the last message received from the
client contains an error in the body.
Table 1: Chat Application Protocol. Angular brackets (<>) indicate variable content.
20
B Socket Interface Reference
This appendix lists multiple functions from Python’s socket library that can help you get started.
You can find more extensive documentation at https://docs.python.org/3/library/socket.
html.
socket
You can create a new socket using the socket function. You can use this socket to either initiate,
or respond to, a connection request. The parameters specify the network-layer and transportlayer protocol.
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connect
Establish a connection using a socket. The parameter is a tuple specifying the network-layer and
transport-layer address. The first parameter is a string containing an IP address or a domain
name. The second parameter is an integer containing the port number.
host_port = ("127.0.0.1", 4321)
sock.connect(host_port)
send
send sends bytes over a socket. Depending on the number of bytes that need to be sent, the
available bu↵er space at the sender, and the number of bytes that can be accepted at the receiver,
it may not be possible to send the complete bu↵er at once. Therefore, the function sends whatever
it can and returns the number of bytes it sent. It is up to the programmer to keep calling send
until all bytes are sent.
string_bytes = "Sockets are great!".encode("utf-8")
bytes_len = len(string_bytes)
num_bytes_to_send = bytes_len
while num_bytes_to_send > 0:
# Sometimes, the operating system cannot send everything immediately.
# For example, the sending buffer may be full.
# send returns the number of bytes that were sent.
num_bytes_to_send -= sock.send(string_bytes[bytes_len-num_bytes_to_send:])
recv
recv receives bytes over a socket and returns a bu↵er containing these bytes. This function is
blocking, meaning the function will wait until there are bytes available.
# Waiting until data comes in
# Receive at most 4096 bytes.
data = sock.recv(4096)
if not data:
print("Socket is closed.")
21
else:
print("Socket has data.")
Exceptions
Python uses exceptions to handle errors. You can handle errors by placing function calls which
can return an error in try-except blocks.
try:
sock.send("how to handle errors?".encode("utf-8"))
answer = sock.recv(4096)
except OSError as msg:
print(msg)
22
C Threading Interface Reference
This reference shows multiple functions from Python’s threading library. For more extensive documentation, see the Python Docs website: https://docs.python.org/3/library/threading.
html
thread
Creating a new thread is done using the threading.Thread function. When creating a new
thread, you need to pass the function that needs to be executed in a separate thread, along with
the arguments that function requires. In the example below, we create a Thread object that will
run the print function in a separate thread.
import threading
t = threading.Thread(target=print, args=("hello", "world"))
The args parameter must be a tuple. If the function only takes one argument, you can add
an additional “,” to create it.
>>> a = ("hello", "world")
>>> b = ("hello")
>>> c = ("hello",)
>>> type(a)
<class 'tuple'>
>>> type(b)
<class 'str'>
>>> type(c)
<class 'tuple'>
start
Run the function you specified in a new thread by calling start.
t.start()
join
Wait for the function and thread to finish by calling join.
t.join()
23
D Commands to Configure the Unreliable Chat Server
Message Sent by Description
SET DROP <value>\n Client Set message drop probability. Value
between 0 and 1.
SET FLIP <value>\n Client Set bit flip probability. Value between 0
and 1.
SET BURST <value>\n Client Set burst error probability.
SET BURST-LEN <lower> <upper>\n Client Configure the burst error length. Default
is 3.
SET DELAY <value>\n Client Set message delay probability.
SET DELAY-LEN <lower> <upper>\n Client Configure the delay length in seconds.
Default is 5.
GET <name>\n Client Get the current value of a setting.
VALUE <name> <value> (<upper>)\n Server The name and value(s) of a setting.
RESET\n Client Set all values to their defaults.
SET-OK\n Server Value received and set.
Table 2: Chat Application Protocol Extension for Unreliable Chat Server. Default value is 0
unless indicated otherwise. Angular brackets (<>) indicate variable content.
24
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。