Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me to design the code for this problem in Java. Use Sockets for communication between processes. Your task is to write a client

Please help me to design the code for this problem in Java.

Use Sockets for communication between processes. Your task is to write a client and a server.

The client and server will demonstrate a message posting system. The server will maintain messages posted by clients, which clients can retrieve and view.

The client will: 1) Accept a machine name and port number to connect to as command line arguments. 2) Connect to the server. 3) Prompt for and send the users name. 4) Present the following menu of choices to the user: a. Display the names of all known users. b. Display the names of all currently connected users. c. Send a text message to a particular user. d. Send a text message to all currently connected users. e. Send a text message to all known users. f. Get my messages. g. Exit. 5) Interact with the server to support the menu choices. 6) Ask the user for the next choice or exit.

The server will: 1) Accept a port number as a command line argument. 2) Accept connections from clients. 3) Create a new thread for each client. 4) Store messages sent to each user. 5) End by termination with control-C.

The server thread will: 1) Accept and process requests from the client. 2) Add the users name to the list of known users. 3) Provide mutual exclusion protection for the data structure that stores the messages. 4) Send only the minimal data needed to the client, not the menu or other UI text. Other rules:

1) Each client transaction should interact with the server. Clients will not communicate directly with each other. 2) Configuration: your server should support multiple different clients at the same time, but should not allow the same user name to have more than one connection at the same time. 3) Authentication: assume the client has privileges to use the systemdo not require a password. 4) Limits: you can assume a maximum of 100 known users, and a maximum of 10 messages each, where each message is at most 80 characters long. 5) Persistence: when the server exits the messages it is storing are lost. They will not be saved to a file. When a user gets their messages, those messages are removed from the server. 6) Users: a known user is any user who has connected during the server session, but may or may not be currently connected. Also, a message sent to an unknown user makes them known. 7) Errors: obvious errors should be caught and reported. For example, an invalid menu choice. 8) Output: your output should use the same wording and format as the sample output.

Sample output (assumes Joe has already connected):

Client output for user Sue:

>client cs1 2005

Connecting to cs1:2005

Enter your name: Sue

1. Display the names of all known users. 2. Display the names of all currently connected users. 3. Send a text message to a particular user. 4. Send a text message to all currently connected users. 5. Send a text message to all known users. 6. Get my messages. 7. Exit. Enter your choice: 1

Known users: 1. Sue 2. Joe

1. Display the names of all known users. 2. Display the names of all currently connected users. 3. Send a text message to a particular user. 4. Send a text message to all currently connected users. 5. Send a text message to all known users. 6. Get my messages. 7. Exit. Enter your choice: 3

Enter recipient's name: Joe Enter a message: Hello Joe

Message posted to Joe

? 1. Display the names of all known users. 2. Display the names of all currently connected users. 3. Send a text message to a particular user. 4. Send a text message to all currently connected users. 5. Send a text message to all known users. 6. Get my messages. 7. Exit. Enter your choice: 6

Your messages: 1. From Joe, 04/11/13 03:14 PM, Hello Sue 2. From Joe, 04/11/13 03:15 PM, Whats new?

1. Display the names of all known users. 2. Display the names of all currently connected users. 3. Send a text message to a particular user. 4. Send a text message to all currently connected users. 5. Send a text message to all known users. 6. Get my messages. 7. Exit. Enter your choice: 7

Server sample output:

>server 2005

04/11/13, 3:10 PM, Connection by known user Sue. 04/11/13, 3:12 PM, Connection by unknown user Joe. 04/11/13, 3:13 PM, Sue displays all known users. 04/11/13, 3:13 PM, Sue posts a message for Joe. 04/11/13, 3:13 PM, Joe displays all connected users. 04/11/13, 3:14 PM, Joe posts a message for Sue. 04/11/13, 3:15 PM, Joe posts a message for Sue. 04/11/13, 3:17 PM, Sue gets messages. 04/11/13, 3:20 PM, Sue exits 04/11/13, 3:21 PM, Joe exits

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

=+Are you legally able to work in the United States?

Answered: 1 week ago