domainleft.blogg.se

Knockknock design
Knockknock design




  1. #Knockknock design how to
  2. #Knockknock design code

New InputStreamReader(clientSocket. New PrintWriter(clientSocket.getOutputStream(), true) However, a modified version of the program is provided inĪfter the server successfully establishes a connection with a client, it communicates with the client using this code: The server can communicate with the client over this new Socket and continue to listen for client connection requests on the original ServerSocket This particular version of the program doesn't listen for more client connection requests. Socket object which is bound to the same local port and has its remote address and remote port set to that of the client. When a connection is requested and successfully established, the accept method returns a new (Let's assume that you ran the server program KnockKnockServer on the computer named .) In this example, the server is running on the port number specified by the first command-line argument. For example, this command starts the server program KnockKnockServer so that it listens on port 4444:Īccept method waits until a client starts up and requests a connection on the host and port of this server.

knockknock design

When running this server, choose a port that is not already dedicated to some other service.

#Knockknock design code

ServerSocket object to listen on a specific port (see the statement in bold in the following code segment). The server program begins by creating a new This section walks through the code that implements the Knock Knock server program,

#Knockknock design how to

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

knockknock design

This object implements the protocol-the language that the client and server have agreed to use to communicate. 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. KnockKnockServer, which is similar toĮchoServer, 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 server program is implemented by two classes: Since the blind are unable to benefit from street signs, directional signs, and street indicators for bus stops, restrooms, hospitals, and other public facilities, Knock-Knock Bricks are designed to help the blind in determining various navigational information with their canes. KnockKnockClient, and is very similar to theĮchoClient example from the previous section. The client program is implemented by a single class, The example consists of two independently running Java programs: the client program and the server program. Server: "Knock knock!" Client: "Who's there?" Server: "Dexter." Client: "Dexter who?" Server: "Dexter halls with boughs of holly." Client: "Groan." Knock Knock jokes are favored by children and are usually vehicles for bad puns. The server in the client/server pair serves up Knock Knock jokes. This section shows you how to write a server and the client that goes with it.






Knockknock design