Print Friendly and PDF
18.3 Distinguish between connection-oriented and connectionless network services. ANS: Connection-oriented services maintain a connection while data is being transferred. Connectionless services do not maintain a connection. Connection-oriented services are generally slower but more reliable.
18.3 Distinguish between connection-oriented and connectionless network services. ?

ANS: Connection-oriented services maintain a connection while data is being transferred.
Connectionless services do not maintain a connection. Connection-oriented services are generally slower but more reliable.


18.4 How does a client determine the host name of the client computer?
ANS: InetAddress.getLocalHost().getHostName().

18.5 Under what circumstances would a SocketException be thrown?
ANS: If a DatagramSocket cannot be constructed properly, a SocketException is
thrown.

18.6 How can a client get a line of text from a server?
ANS: Through the Socket using a stream object (e.g., such as ObjectInputStream).

18.7 Describe how a client connects to a server.

ANS: A client can read a file through a URL connection by creating a URL object and issuing an openStream method call on the URL object. The openStream call returns an InputStream object that can be used to read bytes from the file. Also, a DataInputStream object can be chained to the InputStream returned from openStream to allow other data types to be read from the file on the server.

18.8 Describe how a server sends data to a client.?

ANS: A client connects to the server by creating a socket using the Socket class constructor. The name of the server and the port to connect to are passed to the Socket constructor.
Information can be exchanged between the client and server using the socket’s InputStream and OutputStream.

18.9 Describe how to prepare a server to receive a stream-based connection request from a single client.?

ANS: First a ServerSocket object must be created and associated with a port on the server
computer. If the ServerSocket is created properly, a call to the accept method can be issued on the ServerSocket object. This call will wait for a client to connect. When a client
connects, a Socket object is returned from the accept call. The Socket object is used to
get the InputStream and OutputStream objects for communication with the client.

18.10 Describe how to prepare a server to receive connection requests from multiple clients if each client that connects should be processed concurrently with all other connected clients.?

ANS: First a ServerSocketChannel object must be created and associated with a port on
the server computer, configure the channel so that it works in nonblocking mode. Then register a Selector (the interest set contains OP_ACCEPT operation) to the channel. If the
ServerSocketChannel is created properly and ready to accept new connections, a call to the accept method can be issued on the ServerSocketChannel, a SocketChannel object is returned from the accept call. The SocketChannel object is used to communicate with the client.

18.11 How does a server listen for connections at a port?
ANS: The ServerSocket accept method (or the ServerSocketChannel accept method) is used.

18.12 What determines how many connect requests from clients can wait in a queue to connect to
a server?

ANS: When the ServerSocket object is created on the server, the second argument to the
ServerSocket constructor specifies the "queue length" (the number of clients that can wait
to be processed by the server).


18.13 As described in the text, what reasons might cause a server to refuse a connection request from a client?

ANS: A server usually has a capacity of the number of clients that can wait for a connection
and be processed by the server. If the queue of clients is full, client connections are refused.
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: