Java代写|COMP2221 Coursework: Client and multi-threaded server

这是一个英国的Java代写案例

Requirements

To get started, download the file cwk.zip from Minerva and unarchive it using unzip cwk.zip.

You should have a directory cwk containing the following files and subdirectories:

cwk — client — Client.java
| –
– server — Server.java

Empty class files for the client and server have been provided. Do not change the names of these files, as we will assume these file and class names when assessing. You are free to add additional .java files to the client and server directories but your submission must work when the procedure described below is followed.

The requirements for the server application are as follows:

• Accept the number of lists, and the maximum number of members per list, as command line arguments when launched. All lists should be empty initially.

• Run continuously.

• Use an Executor to manage a fixed thread-pool with 25 connections.

• Store the members of each list, where each member is represented by a single String.

• Return information about the lists, and attempt to add new members to a list, when requested by a client (see below).

• Create the file log.txt on the server directory and log every client request, with one line per request, in the following format:

date|time|client IP address|request.

Nothing else should be output to the log file.

The requirements for the client application are as follows:

• Accept one of the following commands as command line arguments, and performs the stated task in conjunction with the server:

• totals: Displays the number of lists, the maximum per list, and the current number of members of each list.

• list n: Display every member in the given list, one member per line.

• join n name: Attempt to add a member name to list n, and return to the user Success if this was successful, or Failed if not.

• For the join command, full names with spaces should be enclosed in quotes so that they are parsed as a single String; see examples below.

• Quits after completing any one command.

Your server application should listen to a port number in the range 9000 to 9999, but otherwise you are free to choose the port number. Both the client and the server should run on the same machine, i.e. with hostname localhost.

Lists are index by number starting from 1; so if there are 3 lists, the client should reference them as lists 1, 2 and 3, not 0, 1 and 2.

All communication between the client and server must use sockets. Your solution must use TCP,but other details of the communication protocol between the server and the clients are not specified.

You are free to devise any protocol you wish, provided the requirements are met.

Neither the client nor the server should expect interaction from the user once they are executed.

In particular, instructions to the Client application must be via command line arguments. In the case of an invalid input, your client application should quit with a meaningful error message.

Your code should adhere to the Java coding standards described in JavaCodingStandards.pdf on Minerva.

Example session

Suppose you want 3 lists, each with a maximum of 2 members. Then you would cd to cwk/server and launch the server using

java Server 3 2

Now in another tab or shell, cd to cwk/client. If you execute the following commands, the output should be something like that shown.

java Client totals

There are 3 list(s), each with a maximum size of 2.

List 1 has 0 member(s).
List 2 has 0 member(s).
List 3 has 0 member(s).

java Client join 1 “William Haydon”
Success.

java Client join 1 “Constance Sachs”
Success.

java Client join 3 “Gerald Westerby”
Success.

java Client join 1 “Percival Alleline”
Failed.

java Client list 1
William Haydon
Constance Sachs

java Client totals

There are 3 lists with a maximum size of 2.

List 1 has 2 member(s).
List 2 has 0 member(s).
List 3 has 1 member(s).

Note your application does not need to follow exactly the same output as in this example, as long as the requirements above are followed.