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: 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |