Objective: write multi-threaded server communicate with clients connected over a Socket and which objects are sent between client and the server.
You should create a task in a client / server application where the server generates mathematical expressions (eg 1 + 1) that is sent over the network to the client. Client consists of a graphical user interface where users can enter their response to expression then the expression is sent back to the server. The server calculates the expression and
checks if the user typed the correct answer. The result is sent back to the client.
You should start by writing a class to represent the mattematiska expression (mattetal). Matt majority consists of two integers (int), an operator (String) and a response (String). These should be kept as instance variables in the class. The class will also be a public static constant of valid operators. The valid operators are +
(addition), - (subtraction), / (division) and * (multiplication).
There should be two constructors. The first takes three arguments, namely the two centuries and operator. The second takes no arguments but randomly values (0 - 20) for the two centuries, and the operator, of the valid operators, which apply. There should be get-methods for all instance variables and a set method to change / set the value of answer. In addition to this, toString () superimposed so that the returned carpet century strict accordance with the form: number1 operator number2 (eg, 1 +1 or 88 / 4 etc).
Server to handle multiple simultaneous clients, and where communication with each client is in a separate thread. When the server starts you should be able to specify (as a arguments to the application) which port the server will listen on for connecting clients. Indicated no port is the port number of 10,005 used.
You should have a graphical user interface. It should be possible to see (get information on) when a client joins and the
address the client has, and when the client quit (disconnects).
The client must have a graphical user interface in which dull speeches from the server is displayed and in which the user must enter their response by then will be sent to the server calculation. You may choose the appropriate components for this. When the client starts to you can specify (as an argument to the application) the address and port server has. Listed no address and port to the address "localhost" and port number
All communication between server and client is done with Object Input Stream and Object Output Stream. Communication can be described as:
1. The server starts and listens for clients to connect.
2nd When a client connects, a new thread to process the client.
3rd The server creates a new mattetal with random values and sends this
(objects) to the client.
4th The client receives the item, presenting most of the dull user and waits for the user to enter their response.
5th The user types the answer stored in the object (through the set method) whereupon the client sends the item back to the server.
6th The server receives the carpet's (which now contains the user's response)
7th The server calculates the response (using the GET method to retrieve the two rates and operator) and compare the response to the user specified.
8th The server sends the client a boolean indicating if the user's response is correct (true) or false (false).
9th The client receives the result (a boolean) and presents it in an appropriate manner for the user.
10th Repeat step 3 through step 9 until the user closes the client.
The user of the client shall be notified accordingly if any fault occurs in any of points or when establishing communication with the server (for example, the server does not reached or the input / output streams can not be created). Remember to close the open streams and / or socket in case something goes wrong or when the client ends. Create separate jar files
for server and client.
Server and the client shall be extended by the following:
The user of the client is via a menu selection to choose (JFileChooser), a text file from the hard drive. The text file, we assume contains mattetal including responses to client sends to the server. The server notifies the numbers and send a new file showing the user's answer was correct or not. The file is saved with appropriate names the user's hard drive. This activity will take place in separate threads of both the server and
client (while the server notifies the user should be able to answer mattetal as usual).
The user sends text file looks like the following formats:
1 +1 = 2
2 * 2 = 4
10 / 4 = 2
100-80 = 15
The text file, the server sends back is as the following format:
1 +1 = 2 (right)
2 * 2 = 4 (right)
10 / 4 = 2 (right) NOTE: Integer division
10-80 = 15 (error)
When the server is started, a separate thread is created which is responsible for receiving files and correcting them. This thread does not need to cope with multiple simultaneous users. "Corrections" thread to listen for connections on a port number 10 higher than
server listens for clients. "Corrections"-thread is consciously pause at 5:00
milliseconds between each speech to simulate the correction takes a long time. The user shall be notified in an appropriate manner when the result of the fix is complete. You may choose the appropriate streams to transfer the file or content.