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

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 Simple Chat, if the server shuts down while a client is connected, the client does...
In Simple Chat, if the server shuts down while a client is connected, the client does not respond, and continues to wait for messages. Modify the client so that it responds to the shutdown of server by printing a message saying the server has shut down, and quitting. (look at the methods called connectionClosed and connectionException). //ChatClient.java // This file contains material supporting section 3.7 of the textbook: // "Object Oriented Software Engineering" and is issued under the open-source //...
Write a Java program that establishes a TCP connection with a mail server through the socket...
Write a Java program that establishes a TCP connection with a mail server through the socket interface, and sends an email message. Your program sends SMTP commands to local mail server, receives and processes SMTP commands from local mail server. It sends email message to one recipient at a time. The email message contains a typical message header and a message body. Here is a skeleton of the code you'll need to write: import java.io.*; import java.net.*; public class EmailSender...
AWS screenshot of a view of the web browser connection to your web server via the...
AWS screenshot of a view of the web browser connection to your web server via the load balancer (step 5 of this lab document).
In this part, you will implement a Server class that will accept only one connection, process...
In this part, you will implement a Server class that will accept only one connection, process its requests, and then the Server will end. Create a Server class in the package edu.ucdenver.server The constructor should take the port and backlog to open the server. The server should implement the Runnable interface. Override the following public methods: public void run() This will implement your server. Similar to runServer() from our lecture examples. Upon a client connection, the server will listen for...
Develop a client /server talk application in C or C++. You should run your server program...
Develop a client /server talk application in C or C++. You should run your server program first, and then open another window if you use loopback to connect the local host again, or you may go to another machine to run the client program that will connect to the server program. In this case you must find the server’s IP address first, and then connect to it. If you use loopback, your procedure may look like: ➢ Server Server is...
The RN in charge accepts a client to the unit with an exacerbation of Crohn’s disease....
The RN in charge accepts a client to the unit with an exacerbation of Crohn’s disease. The 20-year-old female client is alert and oriented and has been taking azathioprine. Which room assignment will the RN make for this client? Semi-private room, with another client with Crohn’s. Private room, with private bathroom. Private room, across from the nurse’s station. Semi-private room, with older adult female who is alert and oriented. unanswered 12.0 M3Q_N213 5.0 points possible (graded, results hidden) What is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT