Computer Science, asked by kulkarniprathmesh171, 9 months ago

Write the constructor to allow the server for waiting queue

Answers

Answered by rasmiyap
7

Answer:

This section shows you how to write a server and the client that goes with it. The server in the client/server pair serves up Knock Knock jokes. Knock Knock jokes are favored by children and are usually vehicles for bad puns. They go like this:

Server: "Knock knock!"

Client: "Who's there?"

Server: "Dexter."

Client: "Dexter who?"

Server: "Dexter halls with boughs of holly."

Client: "Groan."

The example consists of two independently running Java programs: the client program and the server program. The client program is implemented by a single class, KnockKnockClient, and is very similar to the EchoClient example from the previous section. The server program is implemented by two classes: KnockKnockServer and KnockKnockProtocol. KnockKnockServer, which is similar to EchoServer, contains the main method for the server program and performs the work of listening to the port, establishing connections, and reading from and writing to the socket. The class KnockKnockProtocol serves up the jokes. It keeps track of the current joke, the current state (sent knock knock, sent clue, and so on), and returns the various text pieces of the joke depending on the current state. This object implements the protocol—the language that the client and server have agreed to use to communicate.

The following section looks in detail at each class in both the client and the server and then shows you how to run them.

Answered by mindfulmaisel
3

Constructor that allow the server for waiting queue:

Explanation:

  • public ServerSocket(int port, int queueLength) throws BindException, IOException

  • This constructor open the server on the given port in its parameter with a waiting queue length.

  • The queueLength argument sets the length of queue for number of incoming connections that are allowed.

Below is the example of accepting only 100 incoming connections.

try {

ServerSocket httpd = new ServerSocket(5776, 100);

}

catch (IOException ex) {

System.err.println(ex);

}

hence, this is the Constructor that allow the server for waiting queue

Similar questions