Create Classname Name Tostring
Create Classname Name Tostring
1
Create a server application that can accept connection from the client. The client should be able to send textual messages to the server (the
messages are terminated by newline), and the server should respond by sending back the message to the user. The server should listen on the
port 2345.
The client should be a simple socket client program that send the message that the user typed and prints out the servers response:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
while (true) {
System.out.print("> ");
out.println(line);
When the user sends a message: create <classname> <name> <list of quoted strings> , the server should create a new object using reflection.
The server should invoke the correct constructor of the class classname . The server should store the resulting object for the key name and
respond with its toString() value.
The strings will not contain spaces or newlines. Invoking the constructor with different arguments than the declared parameters results in an
exception that can be caught.
Example:
- 42
2
Modify the server to enable multiple clients connecting to the same server at the same time.
When the user sends a get <name> command, the server should respond with the toString() value of the object stored for name .
When using the create operation, if the user gives simple names instead of quoted strings, than the already existing objects will be used as
parameters.
- 42
- 3
3
When the user sends exec <obj> <meth> <store> <list of arguments> the server should execute the method meth on the object obj , with
the given arguments (quotes strings or object names), store the result for the name store .
- 42
- 3
- 0
4
The server should handle the following errors:
It should also be able to resolve cases when there are overloaded methods, and should be able to select the correct method for the arguments.
The quoted strings may contain spaces. Modify the server to handle spaces inside quotes.
- 42
- 3
- 0
- [Point [x=43, y=3], Point [x=41, y=3], Point [x=43, y=4], Point [x=43, y=2], Point [x=41, y=4], Point [x=41, y=2], Point [x=42, y=
> get n
- [Point [x=43, y=3], Point [x=41, y=3], Point [x=43, y=4], Point [x=43, y=2], Point [x=41, y=4], Point [x=41, y=2], Point [x=42, y=
> get n
- [Point [x=43, y=3], Point [x=41, y=3], Point [x=43, y=4], Point [x=43, y=2], Point [x=41, y=4], Point [x=41, y=2], Point [x=42, y=