Question
Java Multi-threaded phone server A Client will: Request a connection with the server Send three types of messages through established connection: STORE messages containing name
Java Multi-threaded phone server
A Client will:
Request a connection with the server
Send three types of messages through established connection:
STORE messages containing name and phone number
GET messages containing requests for phone number
REMOVE messages containing requests to remove a number from the list
Server will:
Accept requested connections and support multiple connections
Maintain an appropriate data structure (a list) that holds data received from a client. The data stored on server is a list of names and phone numbers which is empty at startup. It is not persistent.
Process messages received from the client:
If message is STORE with a pair of name and number, server will have to update the list of phone numbers.
If message is GET with a request (a name as a content), server has to send to the client the phone number of this name stored in the list
If message is REMOVE with a name, server has to remove this name and number associated with this name from the list.
Client request commands and its format:
STORE Name Phone number
GET Name
REMOVE Name Server response code and meaning:
Data message:
200
Phone number Acknowledgement message:
100 OK
Error message:
300 " Not Found"
Message not understood:
400 "Bad request"
The structure of the Phone server is shown below:
import java.io.*;
import java.util.*;
import java.net.*;
public class PhoneServer {
// The port number on which the server will be listening
private static int port = 2014;
// The server socket.
private static ServerSocket listener = null;
// The client socket.
private static Socket clientSocket = null;
public static void main(String[] args)throws Exception
{
/** Open a server socket on the specified port number(2014)
and monitor the port for connection requests. When a
connection request is received, create a client request
thread, passing to its constructor a reference to the
Socket object that represents the established connection
with the client.
*/
}
}
class ClientThread extends Thread {
Socket socket; //constructor
public ClientThread(Socket socket) { this.socket = socket; }
//implement the run method
public void run() { handleConnection(socket);
} //implement the handleConnection method here.
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started