Chapter 25: Networking Please send suggestions and errata to y.daniel.liang@gmail.com. Indicate which book you are using. Thanks! 1 Section 25.2 Client/Server Computing When creating a server on a port that is already in use, __________. A. java.net.BindException occurs. B. the server is created with no problems. C. the server is blocked until the port is available. D. the server encounters a fatal error and must be terminated. The correct answer is A Your answer is correct 2 When creating a client on a server port that is already in use, __________. A. the client can connect to the server regardless of whether the port is in use. B. java.net.BindException occurs. C. the client is blocked until the port is available. D. the client encounters a fatal error and must be terminated. The correct answer is A Your answer is correct Explanation: To connect to a client, the server creates a client socket from the ServerSocket. You can create any number of client sockets on the server side to connect to a client on the Internet. 3 The server listens for a connection request from a client using the following statement: A. Socket s = new Socket(ServerName, port); B. Socket s = serverSocket.accept() C. Socket s = serverSocket.getSocket() D. Socket s = new Socket(ServerName); The correct answer is B Your answer A is incorrect 4 The client requests a connection to a server using the following statement: A. Socket s = new Socket(ServerName, port); B. Socket s = serverSocket.accept(); C. Socket s = serverSocket.getSocket(); D. Socket s = new Socket(ServerName); The correct answer is A Your answer is correct 5 When a client requests connection to a server that has not yet started, __________. A. java.net.BindException occurs. B. java.net.ConnectionException occurs. C. the client is blocked until the server is started. D. the client encounters a fatal error and must be terminated. The correct answer is B Your answer A is incorrect 6 To connect to a server running on the same machine with the client, which of the following can be used for the hostname? A. "localhost" B. "127.0.0.1" C. InetAddress.getLocalHost(), D. All of the above. The correct answer is D Your answer A is incorrect 7 To create an InputStream on a socket s, you use __________. A. InputStream in = new InputStream(s); B. InputStream in = s.getInputStream(); C. InputStream in = s.obtainInputStream(); D. InputStream in = s.getStream(); The correct answer is B Your answer A is incorrect 8 3 The InetAddress Class 8. ______________ models an IP address, which can be used to find the host name and IP address of the client. A. The ServerSocket class B. The Socket class C. The InetAddress class D. The Connection interface The correct answer is C Your answer A is incorrect 9 You can invoke ______________ on a Socket object, say socket, to obtain an InetAddress object. A. socket.InetAddress(); B. socket.getInetAddress(); C. socket.obtainInetAddress(); D. socket.retrieveInetAddress(); The correct answer is B Your answer A is incorrect 10 The ____________ method in the InetAddress class returns the IP address. A. getIP() B. getIPAddress() C. getHostAddress() D. getAddress() The correct answer is C 11 Your answer A is incorrect Section 25.4 Serving Multiple Clients A ServerSocket can connect to ________ clients. A. one B. two C. ten D. unlimited number of The correct answer is D 12 Your answer A is incorrect Section 25.5 Applet Clients You can obtain the server?s hostname by invoking _________ on an applet. A. getCodeBase().host() B. getCodeBase().getHost() C. getCodeBase().hostName() D. getCodeBase().getHostName() The correct answer is B 13 Your answer A is incorrect Section 25.6 Sending and Receiving Objects To obtain an ObjectInputStream from a socket, use ________. A. socket.getInputStream() B. socket.getObjectStream() C. socket.getObjectInputStream() D. socket.objectInputStream() E. new ObjectInputStream(socket.getInputStream()); The correct answer is E Your answer A is incorrect 14 To obtain an ObjectOutputStream from a socket, use ________. A. socket.getOutputStream() B. socket.getObjectStream() C. socket.getObjectOutputStream() D. socket.objectOutputStream() E. new ObjectOutputStream(socket.getOutputStream()) The correct answer is E 15 Your answer A is incorrect Section 25.7 Retrieving Files from Web Servers To create an InputStream to read from a file on a Web server, you use the class __________. A. URL; B. Server; C. ServerSocket; D. ServerStream; The correct answer is A Your answer is correct 16 To create an InputStream to read from a file on a Web server, you use the method __________ in the URL class. A. getInputStream(); B. obtainInputStream(); C. openStream(); D. connectStream(); The correct answer is C Your answer A is incorrect