Question

In: Computer Science

The client connects to the server. The server accepts the connection. The client sends a line...

  • The client connects to the server.
  • The server accepts the connection.
  • The client sends a line of text containing only SHAKESPEARE_COUNTS.
  • The server sends back a sequence of integers. The number of integers in that list specifies the number of words in each insult; the numbers themselves specify how many possible words there are in each position. So, for example, if you received the output 15 20 30, it would indicate that insults are three words long, with 15 possible choices for the first word, 20 possible choices for the second, and 30 for the third.
  • The client sends a line of text containing SHAKESPEARE_INSULT, followed by a space, followed by a sequence of integers separated by spaces. Each of the integers chooses a word in one of the available positions, so if SHAKESPEARE_COUNTS returned 15 20 30, the client would need to send exactly three integers along with SHAKESPEARE_INSULT, with the first being between 1 and 15 (inclusive), the second being between 1 and 20 (inclusive), and the third being between 1 and 30 (inclusive).
  • The server sends back one line of text, which is the insult generated from the chosen words.
  • The client sends a line of text containing only SHAKESPEARE_GOODBYE.
  • The server sends one line of text, a goodbye message of sorts, and then both sides close the connection; that's it.

(Before you try writing code to solve this problem, I'd suggest experimenting with the server a bit, using PuTTY on Windows, or using telnet or nc on macOS.)

What your program should do is hide all of these details, which means it would do the following:

  • Connect to the server.
  • Send the SHAKESPEARE_COUNTS message, to find out the length of the insult and how many possible words there are in each position.
  • Choose numbers randomly and send them in a SHAKESPEARE_INSULT message.
  • Print the random insult sent back by the server.
  • Send the SHAKESPEARE_GOODBYE message.
  • Print the goodbye message sent back by the server.

Solutions

Expert Solution

I will not be giving the detailed code, just a break-down on how to approach this problem.

Hint1: Qn states a client and server. So at min. there needs to be 2 file.
   File1: Only Server Code, which will keep on listening. Recommendation: Use some tool/package to kee the file running, like Platform.sh, Google Cloud, simpleHTTPServer
   File2: Only client Code. This file will contain only packet sending information
Hint 2: There are dictionaries kept only at the server end. Construct this in any way you feel comfortbale to traverse. A table containing, 10 Names, 15 verbs, 20 insults for e.g {Name: [a,v,b,ag,g,..], Verbs: [is, are,....], Insults: [**s, ***t, ***k, ]

NOTE: If server creation and hosting is not part of syllabus, modify the problem to a simple UI/CLI based interaction. In UI/CLI enter these values as client. In server/program validate these values, and send appropriate response to UI/CLI

Data Flow between C&S

Client    Server                   Remarks


Shakespeare_COUNTS                                             // Client-> Server
                                               15 20 30                // Server -> Client (SizeOf name[], verbs[], and insults[])
Shakespeare_Insults 6 5 3     // Random Nos generated in client, or given by some user input
                                               A am ***t                   // Final result
Shakespeare_GoodBye                                              


Related Solutions

Greetings, Consider a client server model.The server sends the message 'I am the server' to client....
Greetings, Consider a client server model.The server sends the message 'I am the server' to client. Describe and compare in details how the client and server exchange these messages using internet domain in the following two modes. a) connection-oriented modes b) connectionless-oriented modes
Write and test a python program to demonstrate TCP server and client connections. The client sends...
Write and test a python program to demonstrate TCP server and client connections. The client sends a Message containing the 10 float numbers (FloatNumber[]) , and then server replies with a message containing maximum, minimum, and average of these numbers.
A client sends a TCP segment to the server with Sequence Number 1400 and the payload...
A client sends a TCP segment to the server with Sequence Number 1400 and the payload included in the segment is 1399 bytes long. - A. What is the ACK Number in the acknowledgement that is returned from the server? - B. Assume this packet is lost but the following packet is received. What is the ACK Number in the acknowledgement that is returned from the server for this packet? - C. Provide a detailed explanation for part B.
In the provided client and server code, the server can serve to single client at a...
In the provided client and server code, the server can serve to single client at a time. You have to change server.java code so that it can connect and serve multiple clients at the same time. Use multithreading. =============================================================================== import java.io.*; import java.net.*; public class Client { public static void main(String[] args) throws IOException { String serverHostname = new String ("127.0.0.1"); if (args.length > 0) { //pass the hsotname through cmd argument serverHostname = args[0]; } System.out.println ("Attemping to connect...
in Java - implement ftp-server and ftp-client. ftp-server Logging into ftp-server from ftp-client The ftp-server is...
in Java - implement ftp-server and ftp-client. ftp-server Logging into ftp-server from ftp-client The ftp-server is an interactive, command-line program that creates a server socket, and waits for connections. Once connected, the ftp-client can send and receive files with ftp-server until ftp-client logs out. Sending and receiving files The commands sent from the ftp-client to the ftp-server must recognize and handle are these: rename- the ftp-server responds to this command by renaming the named file in its current directory to...
There are many factors that can influence such decision for cloud server and client server. security,...
There are many factors that can influence such decision for cloud server and client server. security, cost, training and more. which would you choose and why ? there are many factors that influenced the decision on a cloud server or client server such as cost, security, training and more. which one would you choose, cost, security,training etc. and why ? cancel that answer
In Java and using JavaFX, write a client/server application with two parts, a server and a...
In Java and using JavaFX, write a client/server application with two parts, a server and a client. Have the client send the server a request to compute whether a number that the user provided is prime. The server responds with yes or no, then the client displays the answer.
In web programming what is the Client-Server model?
In web programming what is the Client-Server model?
In web programming what is the Client-Server model?
In web programming what is the Client-Server model?
Write two python codes for a TCP client and a server using a Socket/Server Socket. The...
Write two python codes for a TCP client and a server using a Socket/Server Socket. The client sends a file name to the server. The server checks if there is any integer value in the file content. If there is an integer number, the server will send a message to the client “Integer exists” otherwise, the message “Free of Integers”
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT