Attached is the question
Parallel Computing and Distributed Systems
Assignment 2 (10 points)
Carefully read the shared client.java and server.java files along with the comments placed per command. Run the server project
first, then run the client project. These projects create a chat between the client and the server. Through the terminal window of the
client, you can start writing some statements, and on clicking enter, you should find these statements on the terminal of the server
side along with responses back from the server displayed on the client side. This chat will keep on until the client sends “exist” as
a command and clicks enter; this will terminate the connection established as well as the read and write streams on the two sides.
Task1 description (5 points):
In this assignment, you will extend these shared files to implement an interactive two-tier communication application using network
sockets. Usually, the client and server applications reside on two different devices (e.g., two computers, a smartphone and a
computer). But, to keep this lab simple, you can run both client and server applications on the same computer.
• If you are running the client and server on the same device, the IP of the server will be “localhost” or “127.0.0.1”
• If you are running the client and server on two different devices over the same network (e.g., your home network), how to know
the IP of the server?
• If you are running the client and server on two different devices over different networks – check the VPN section below.
The client hosts the user-interface layer where the user can send command(s) to the server. The server hosts both the processing
and data layers to handle the incoming commands from the client side on stored data. The data layer at the server side keeps a
dynamic list (ArrayList) of integers (initially empty) named as inputValues to handle (add/remove) data to/from the user.
The user at the client side enters a command through the terminal (e.g., of your IDE) and then waits for a response back from the
server to be able to enter another command. The following table shows the different supported commands that the user can send to
the server side, along with the proper handle from the server side and expected responses. The client side should print a list of the
supported commands to the user to help them write the correct formatted command. If the user sends any other command or a
supported command, but in a different format, the server should ignore the received message and respond with “unsupported
command” without exiting either the client or the server.
A command from the client to the server is a JSON object, with a unique identifier as the key and the actual instruction as the value.
A response from the server to the client is also a JSON object, with the identifier of the instruction as the key and the result as the
value. For example:
• If the user wants to add the number 80 to the server’s list, the user types “Add: 80” and clicks enter.
• The client builds JSON-based command: {“Instruction 1”: “Add: 80”}.
• The server executes the instruction and responds with the following JSON-based response: {“Instruction 1”: “added
successfully”}.
• If the user wants to display the sorted version of the values from the server’s list, the user types “Sort_A” and clicks enter.
• The client builds the following JSON-based command: {“Instruction 2”: “Sort_A”}.
• The server then executes the instruction and responds with the following JSON-based response: {“Instruction 2”: “The sorted
list is {10,20,30,40}”}
On the server side,
o open a terminal (if you are using Linux or Mac) and type “ipconfig getifaddr en0”
o open a CMD (if you are using Window) and type “ifconfig” then search for IPv4
Client Supported Commands Server Reaction and response
Add: x,y,…, z
where x, y, and z can be any integer values (e.g., Add:
74,18)
1- Add the input values to the inputValues list
2- Respond with “added successfully”
Remove: x,y,…, z
where x, y, and z can be any integer values (e.g.,
Remove: 74,18,14)
1- Remove all occurrences of the input values from the
inputValues list
2- Respond with “removed successfully”
Get_Summation 1- Calculate the summation of values in the inputValues list
2- Respond with “The summation is x”
where x is the summation of all values in the list. If empty list or all
elements are zeros, x in the message equals null
Sort_A 1- Sort the values in the inputValues list in ascending order
2- Respond with “The sorted list is {x,y,….z}”
where x,y, and z are elements in the list. If empty list or all elements
are zeros, the message holds {null}
Exit
This is the only command that terminates the interactive
communication.
No action or response required.
Task2 description (5 points):
Your design in task1 should be more efficient allowing the client to batch one or more commands and the server to batch the
corresponding response(s) – we need to use JSON-formatted messages. The client-server communication should send an array of
JSON-objects and get JSON responses. For example:
• Suppose the user wants to add number 80 then sort the array. The user types “Add: 80; Sort_A” and clicks enter.
• The client builds the following JSON-based array of commands:
[{“Instruction 1”: “Add: 80”}, {“Instruction 2”: “Sort_A”}]
• The server then executes the instructions one by one and responds with the following JSON-based array of responses:
[{“Instruction 1”: “Added successfully”}, {“Instruction 2”: “The sorted list is {10,20,80}”}]
Further Resources:
1- JSON Library
The client creates JSON objects for commands and sends them as strings to the server side. The server side converts the received
strings to JSON objects. The server side creates JSON objects for responses and sends them as strings to the client side. The client
displays the responses to the user. Let’s assume the user is friendly enough not to place the exit command in the middle of the
commands’ array to the server.
Use the JSON library you find appropriate (e.g., http://www.java2s.com/Code/Jar/j/Downloadjavajsonjar.htm,
http://www.java2s.com/Code/Jar/j/Downloadjsonsimple11jar.htm)
Do enough search to learn about using the JSON library in Java.
2- Hamachi VPN (This part of the assignment is optional)
Sockets we discussed assume the communicating computers are on the same network and use local IPs. If you are working in a
group, with a team mate is developing and running the client and the other mate is developing and running the server side most
probably you are working in two different networks – thus your team needs a virtual private network, kind of network that allows
two computers on two different networks to see each and communicate with each other. For this assignment, you can use LogMeln
Hamachi (https://vpn.net/), download, install, then run – create a network and share the network ID and password with your
teammate to join.
Submission:
1. Use the IDE you find appropriate to develop your Java programs. Then, create one PDF file where you list/copy the code
you developed for each task with screenshots showing the different commands and reactions/responses (don’t submit a
zip file). Submit the PDF file directly to the folder titled Assignment 2 under the D2L Assignments tab (other formats
will not be accepted).
2. Check the due date on D2L. You can submit your assignment within 24 hours after this due date to be graded out of 50%
of the assignment’s grade. After this grace period, your late submission will not be accepted.