java代写/网络编程/多线程编程/socket编程: A multi threaded Phone server

A multi threaded Phone server

java代写/网络编程/多线程编程/socket编程: 这是一个典型的通过多线程编程网络服务器的程序编写,涉及了java、多线程、tcp协议等网络方面的综合知识,是一个典型的网络编程题目

In this assignment you will develop a multi-threaded phone server, where the processing of each
incoming request will take place inside a separate thread of execution. This allows the server to
service multiple clients in parallel.
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
• 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.
If there is an erroneous message, server should react by sending an appropriate message to
the client.
Clients are a Java console applications that start with a connection request to the server
Server is also a Java console application that starts with an empty list of names and phone
Submit a word file containing the description of your protocol and a zip file of source code of
client and server programs and a screen shot of a sample run.
Client request commands and its format:
STORE Name Phone number
GET 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”

A sample of communication between a client and the phone server.
Client Server

Connection is established
Request/response process starts between client and server
The structure of the Phone server is shown below:
import java.util.*;
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;

public ClientThread(Socket socket)
this.socket = socket;

//implement the run method
public void run()
//implement the handleConnection method here.
Testing: Run the server on command line and then run your client program more than one
time to create a number of clients. For example see a run sample below of the multi-threaded
Talk client/server program with two clients.
Client1 and Client2 are running in parallel and
both are talking to TalkServer at the same time.


邮箱地址不会被公开。 必填项已用*标注