Chapter 33 Networking
Section 33.2 Client/Server Computing
1. 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
#
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
#
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);
#
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);
#
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
#
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. “127.127.127.1”.
#
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();
#
Section 33.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
#
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();
#
10. The method in the InetAddress class returns the IP address.
a. getIP()
b. getIPAddress()
c. getHostAddress()
d. getAddress()
#
Section 33.4 Serving Multiple Clients
11. A ServerSocket can connect to clients.
a. one
b. two
c. ten
d. an unlimited number of
#
Section 33.5 Applet Clients
12. You can obtain the server’s hostname by invoking on an applet.
a. getCodeBase().host()
b. getCodeBase().getHost()
c. getCodeBase().hostName()
d. getCodeBase().getHostName()
#
Section 33.6 Sending and Receiving Objects
13. 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());
#
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())