Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Statement: You are required to produce two programs, chatserver and chatclient. There can be more than one instances of chatclient running at a time

Problem Statement: You are required to produce two programs, chatserver and chatclient. There can be more than one instances of chatclient running at a time and the purpose of chatserver is to provide a link between all the available clients so that they can talk to each other.

Requirements: chatserver: On startup, server will create a socket to receive client connections and messages. One client can send a message to another client via the server. All messaging is done through the server. It means that whenever a client has to send a message to another client; it will send the message with the target clientid to the server to be forwarded to another client. Clients can also send messages to the server to get some information in response. The server if it receives a message for a client, who is not online anymore, respond to the source client with a message that the target client is not online. The server will keep a list of online clients with it and clients can ask about this list by sending a message to the server. The server is also responsible for sending the latest client list to all the clients whenever there is a change in it.

chatclient: On startup, each client will connect to the server and sends its id provided by the user. The server will register this client. Each client is required to send an alive message to the server after regular intervals so that the server is updated about its presence. The server will tell to the client about the length of this interval in response to the connect message. If the server doesnt receive an alive message from some client then it de-lists it and sends the latest list to all online clients. Whenever a client wants to send a message, it sends a message to the server with the target clientid. Clients can also request the latest client list by sending a message to server.

message: A message sent by a process (client/server) to another. It is a null terminated string with the maximum length of 255 bytes (256th byte is null). First 8 bytes are the name of destination, next 8 bytes are the name of the source and the remaining bytes up-to the null byte are the actual message. It means that the actual message length cant be more than 239 bytes. It also implies that a client name cant be more than 8 bytes, and if some client has name less than 8 bytes then you have to perform padding to keep it of 8 Bytes. Moreover, as the server sends the list of online clients through a message and the message length is limited, therefore, either you have to limit the number of concurrent clients or use some other way to send the list in more than one iterations.

Standard/Control Message Formats: The following standard/control messages should be implemented: Connect Syntax: Connect clientid Purpose: automatically sent by a client to the server when the client comes online @Quit Syntax: @Quit Purpose: user types it at the client prompt to end his session Quit Syntax: Quit clientid Purpose: automatically sent by a client to the server when a user requests for session end @List Syntax: @List Purpose: user types it at the client prompt to view the current list of online clients List Syntax: List Purpose: automatically sent by a client to the server when a user requests the list of online clients Alive Syntax: Alive clientid Purpose: automatically sent by client to server after regular intervals that it is still alive General Message to some other client Syntax: (otherclientid) message-statement Purpose: typed by the user at the client prompt when he want to send a message to an online client

Note: In all messages to the server, the destination address is -SERVER-. You can implement server in a way that it can broadcast a single message to all clients by typing destination as ALL or something else, but it is not required. You need to implement a multithreaded server such that each client is connected with the server in a separate thread. The online client list at the server is shared among all the threads and you may be required to use proper thread synchronization method to avoid data inconsistencies.

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

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions