Chapter 22 Networking: Streams-Based Sockets and Datagrams 1143 (Apache web server for windows)

Chapter 22 Networking: Streams-Based Sockets and Datagrams 1143 ANSWERS TO SELF-REVIEW EXERCISES 22.1 a) False. UDP is a connectionless protocol, and TCP is a connection-oriented protocol. b) True. c) False. Packets can be lost, arrive out of order or even be duplicated. d) True. e) False. TcpListener AcceptSocket may be called as often as necessary each call will accept a new connection. f) False. A TcpListenercan listen for connections at only one port at a time. g) False. A UdpClient can send information to any port represented by an IPEndPoint. h) False. Packets may be sent more than once, to make it more likely that at least one copy of each packet arrives. i) True. 22.2 a) System.Net, System.Net.Sockets. b) UdpClient. c) IPAddress. d) stream, datagram. e) Transmission Control Protocol. f) TcpListener. g) TcpClient. h) Network- Stream. EXERCISES 22.3 Use a socket connection to allow a client to specify a file name and have the server send the contents of the file or indicate that the file does not exist. Allow the client to modify the file contents and to send the file back to the server for storage. 22.4 Multithreaded servers are quite popular today, especially because of the increasing use of multiprocessing servers (i.e., servers with more than one processor unit). Modify the simple server application presented in Section 22.4 to be a multithreaded server. Then, use several client applications and have each of them connect to the server simultaneously. 22.5 Create a client/server application for the game of Hangman, using socket connections. The server should randomly pick a word or phrase from a file or a database. After connecting, the client should be allowed to begin guessing. If a client guesses incorrectly five times, the game is over. Display the original phrase or word on the server. Display underscores (for letters that have not been guessed yet) and the letters that have been guessed in the word or phrase on the client. 22.6 Modify the previous exercise to be a connectionless game using datagrams. 22.7 (Modifications to the Multithreaded Tic-Tac-Toe Program) The programs of Fig. 22.5 Fig. 22.7 implement a multithreaded, client/server version of the game Tic-Tac-Toe. Our goal in developing this game was to demonstrate a multithreaded server that could process multiple connections from clients at the same time. The server in the example is really a mediator between the two clients it makes sure that each move is valid and that each client moves in the proper order. The server does not determine who won or lost or whether there was a draw. Also, there is no capability to allow a new game to be played or to terminate an existing game. The following is a list of suggested modifications to the multithreaded Tic-Tac-Toe application: a) Modify class Server to test for a win, loss or draw on each move in the game. When the game is over, send a message to each client that indicates the result of the game. b) Modify class Client to display a button that, when clicked, allows the client to play another game. The button should be enabled only when a game completes. Note that both class Client and class Server must be modified to reset the board and all state information. Also, the other Client should be notified of a new game, so that client can reset its board and state information. c) Modify class Client to provide a button that allows a client to terminate the program at any time. When the button is clicked, the server and the other client should be notified. The server should then wait for a connection from another client so that a new game can begin. d) Modify class Client and class Server so that the loser of a game can choose game piece X or O for the next game. Remember that X always goes first.
Note: If you are looking for cheap and reliable webhost to host and run your web application check Vision coldfusion web hosting services

Leave a Reply