Khalifa University of Science and Technology
Department of Electrical Engineering and Computer Science
ECCE 356 Computer Networks
Spring 2021
Assignment 1 Manual
Introduction:
This document is intended to complement the Assignment 1 document. It includes the steps to execute
the complementary code that requires editing to accomplish the objectives of assignment 1 and explains
the different parts of the code part of the given code.
The supplementary code:
A server/client with multi-thread in C++ language: [Link]
Software required:
Visual Studio 2019
To download it:[Link]
Once downloaded, login with university email for free access
Creating the VS projects:
Open visual studio 2019
Click file -> new> create new project-> empty project from c++, windows
o your software
Import the .cpp files to the source files. Right click on source files-
>add->new existing items.
Import the .h files to the header files. Right click on header files-
>add->new existing items.
For the server, add resources for the client to request:
Right click on resources files->add->new existing items.
Codes Execution Process:
With both projects open, the server code should be first executed. Then, the client code should be run
for the input to be entered and the request to be created. The below figure shows how the codes would
execute. Given that the server is running, the client can request information about a given file. The
name, and the requested
information (size of file or time it was edited). Once the user is entered, the client code encapsulates it
into a request message and sends it to the server. The server extracts the information, constructs the
response and sends it back. The client code then extracts the information from the response and shows
it to the client user.
Execution Snapshots
The following snapshots show the codes during execution where the number correspond to the number
in the process.
Client Server
1
5 and 6
2
8 and 9
Understanding the codes:
Data structures
The client and server codes have a list of structs that allow them to operate described below.
The Request Req struct
Request Interpretation
Hostname of the destination PC
Name of the requested file
The response Resp struct.
Response Interpritation
String holding the response to a request
The message Msg structure:
Type implies the type of the message and is set according to the below enum. Hint: enum consists of
integral constants that start from a default set value.
Length is the length of the message in the buffer.
Buffer holds the message content and is casted to either a request or a response struct based on the
message type.
Type Length
Buffer
Hostname filename response
Variables and constants:
Client main code:
the below
Cast the buffer field of smsg to a
request struct pointer
Initializing the windows sockets
Copy the local host name to the
reqp hostname field
Display name of local host
Copy the file user to the request
file name
Check the request type and set
the smsg type accordingly
Set the length of the send
message
Display status to user and send
message using msg_send function
wait for a message to be received
to the rmsg variable using
msg_recv function
Cast the rmsg buffer to respp and
show the response content
Server main code:
Constructor
Initializing the windows sockets
Display name of local host
Start
Forever loop to keep creating new
threads and accept messages
Run
wait for a message to be received
to the rmsg variable using
msg_recv function
Cast the rmsg buffer to reqp and
show the request content
Check the request type and set
the rmsg response accordingly
Send smsg to the client