Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given the following application-layer networking protocol for a basic client/server application. A client can send tokens (words) to the server which adds them

You are given the following application-layer networking protocol for a basic client/server application. A client can send tokens (words) to the server which adds them to a global tokens list in memory which has a max capacity of ten different tokens (there are no duplicates in this list). The tokens list on the server must always be sorted in lexicographical order. There are three types of requests (SUBMIT, RETRIEVE and QUIT). To further elaborate on the protocol: Client request (a message sent from client to server): SUBMIT token Server: If the global tokens list already contains the submitted token, do not modify the list, just send message OK to the client. If the token is not yet in the list and the list is not yet full, add the token to the list and send message OK to the client. Otherwise (list is full and token is not yet in the list), do not add anything to the list and respond to the client with message ERROR. token stands for any string which doesnt contain whitespace (class Scanner would be useful here). The global tokens list should be kept on the server so that it is sorted in lexicographical order at all times. Choose an appropriate data structure for representing the tokens list. Client request: RETRIEVE Server: Reply with the sorted global list of tokens currently on the server (with the tokens separated by whitespace). If the global tokens list is currently empty, reply with ERROR.

Client request: QUIT Server: Ends the connection to that client. No reply. Example interaction: Client: SUBMIT uvw Server: OK Client: SUBMIT xyz Server: OK Client: SUBMIT uvw Server: OK Client: SUBMIT ab Server: OK Client: RETRIEVE Server: ab uvw xyz Client: QUIT Create a (socket-based, non-servlet) Java program for a multithreaded server which can interact with clients via the Internet (*) in compliance with the given protocol. The server should be able to handle multiple clients concurrently (simultaneously), using multithreading (i.e. any number of clients can be simultaneously connected to a single running instance of the server program and are dealt with by that server at the same time). As specified above, the server should maintain only one single, global tokens list which is never emptied by the server (i.e. not a new empty tokens list for each connecting client). Which means all clients submit their tokens to the same global tokens list on the server, not to different lists. Appropriate measures should be taken to prevent race conditions. Your server should print a log of all client activity processed by it (see example output below). image text in transcribed

Sample client console output (note that other clients can access the server concurrently. Console inputs by the user are IN GREEN): Client: connected to server RETRIEVE Client: sent 'RETRIEVE' to server Client: received message from server 'dog giraffe 200' SUBMIT elephant Client: sent 'SUBMIT elephant' to server Client: received message from server 'OK' SUBMIT rhino Client: sent 'SUBMIT rhino' to server Client: received message from server 'OK' SUBMIT lion Client: sent 'SUBMIT lion' to server Client: received message from server 'OK' SUBMIT leopard Client: sent 'SUBMIT leopard' to server Client: received message from server 'OK' RETRIEVE Client: sent 'RETRIEVE' to server Client: received message from server 'dog donkey elephant giraffe leopard lion rhino turkey 200' SUBMIT leopard Client: sent 'SUBMIT leopard" to server Client: received message from server 'OK' RETRIEVE Client: sent 'RETRIEVE' to server Client: received message from server 'dog donkey elephant giraffe leopard lion rhino turkey zoo SUBMIT hyena Client: sent 'SUBMIT hyena' to server Client: received message from server 'OK' Sample client console output (note that other clients can access the server concurrently. Console inputs by the user are IN GREEN): Client: connected to server RETRIEVE Client: sent 'RETRIEVE' to server Client: received message from server 'dog giraffe 200' SUBMIT elephant Client: sent 'SUBMIT elephant' to server Client: received message from server 'OK' SUBMIT rhino Client: sent 'SUBMIT rhino' to server Client: received message from server 'OK' SUBMIT lion Client: sent 'SUBMIT lion' to server Client: received message from server 'OK' SUBMIT leopard Client: sent 'SUBMIT leopard' to server Client: received message from server 'OK' RETRIEVE Client: sent 'RETRIEVE' to server Client: received message from server 'dog donkey elephant giraffe leopard lion rhino turkey 200' SUBMIT leopard Client: sent 'SUBMIT leopard" to server Client: received message from server 'OK' RETRIEVE Client: sent 'RETRIEVE' to server Client: received message from server 'dog donkey elephant giraffe leopard lion rhino turkey zoo SUBMIT hyena Client: sent 'SUBMIT hyena' to server Client: received message from server 'OK

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

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

=4-1 What is the meaning of least squares in a regression model?

Answered: 1 week ago