8 Sockets for Clients

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

The Socket class overrides only one of the standard methods from java.lang.Object:

toString() *used for debugging

Default port for Telnet?

23

Whois is a simple directory service protocol defined in RFC _____ it was originally designed to keep track of administrators responsible for Internet hosts and domains.

954

Java's Socket class, which is used by both clients and servers, has methods for which of the following operations? A Connect to a remote machine B Send data C Receive data D Bind to a port

A Connect to a remote machine B Send data C Receive data D Bind to a port

Which of the following prefixes is used for searching the group records only and showing all individuals in that group? A Expand or * B Summary or $ C Group D Full or =

A Expand or (asterisk) *

Which of the following fields define the state of a "Whois" object? A host and port B host and interface C client and port D interface and port

A host and port

What is "dict"?

A simple bidirectional TCP protocol, defined in RFC 2229. In this protocol, the client opens a socket to port 2628 on the dict server and sends commands such as "DEFINE eng-lat gold". This tells the server to send a definition of the word gold using its English-to-Latin dictionary

A ___________________ is thrown if you try to construct a Socket or ServerSocket object on a local port that is in use or that you do not have sufficient privileges to use.

BindException

Maximum achievable bandwidth equals

Buffer size divided by latency.

Which of the following methods returns the remote port number to which the socket is connected? A getLocalAddress() B getLocalPort() C getPort() D getInetAddress()

C getPort()

The seven basic socket operations:

Connect to a remote machine Send data Receive data Close a connection Bind to a port Listen for incoming data Accept connections from remote machines on the bound port

A ____________________ is thrown when a connection is refused at the remote host, which usually happens because the host is busy or no process is listening on that port.

ConnectException

What are socket constructors comprised of?

Each Socket constructor specifies the host and the port to connect to. Hosts may be specified as an InetAddress or a String. Remote ports are specified as int values from 1 to 65535. These constructors can also specify where to initiate the connection from locally (uncommon): public Socket(String host, int port, InetAddress interface, int localPort) throws IOException, UnknownHostException public Socket(InetAddress host, int port, InetAddress interface, int localPort) throws IOException

The class of service is stored in an eight-bit field called __________ in the IP header.

IP_TOS Java lets you inspect and set the value a socket places in this field using these two methods:

What is DSCP?

In 21st-century TCP stacks, the high-order six bits of IP_TOS contain a Differentiated Services Code Point (DSCP) value and the low-order two bits contain an Explicit Congestion Notification (ECN) value. The DSCP thus has room for up to 26 different traffic classes. However, it's up to individual networks and routers to specify exactly what the 64 different possible DSCP values mean.

A ______________________ indicates that the connection has timed out.

NoRouteToHostException

By default, Java ignores urgent data received from a socket. However, if you want to receive urgent data inline with regular data, you need to set the _______________ option to true

OOBINLINE

Socket objects have several properties that are accessible through getter methods:

Remote address Remote port Local address Local port *There are no setter methods. These properties are set as soon as the socket connects, and are fixed from there on.

If ____________ is turned on, the client occasionally sends a data packet over an idle connection (most commonly once every two hours), just to make sure the server hasn't crashed.

SO_KEEPALIVE

The _____________option specifies what to do with datagrams that have not yet been sent when a socket is closed.

SO_LINGER *By default, the close() method returns immediately; but the system still tries to send any remaining data. If the linger time is set to zero, any unsent packets are thrown away when the socket is closed. If SO_LINGER is turned on and the linger time is any positive value, the close() method blocks while waiting the specified number of seconds for the data to be sent and the acknowledgments to be received.

If the ______________ is turned on (it's turned off by default), another socket is allowed to bind to the port even while data may be outstanding for the previous socket.

SO_REUSEADDR

The ______________ option controls the suggested send buffer size used for network input. The ____________ option controls the suggested send buffer size used for network output:

SO_SND, SO_RCVBUF *Although it looks like you should be able to set the send and receive buffers independently, the buffer is usually set to the smaller of these two. *Generally, transfers of large, continuous blocks of data, which are common in file transfer protocols such as FTP and HTTP, benefit from large buffers, whereas the smaller transfers of interactive sessions, such as Telnet and many games, do not.

Normally when you try to read data from a socket, the read() call blocks as long as necessary to get enough bytes. By setting _______________ you ensure that the call will not block for more than a fixed number of milliseconds.

SO_TIMEOUT *When the timeout expires, an InterruptedIOException is thrown

The primary purpose of the ____________ class is to provide a convenient store for transient socket connection information such as the IP address and port that can be reused to create new sockets, even after the original socket is disconnected and garbage collected.

SocketAddress

The primary purpose of the _________________ class is to provide a convenient store for transient socket connection information such as the IP address and port that can be reused to create new sockets, even after the original socket is disconnected and garbage collected.

SocketAddress *return "null" of socket is not yet connected *"InetSocketAddress" is only subclass

Benefits of Sockets:

Sockets allow the programmer to treat a network connection as just another stream onto which bytes can be written and from which bytes can be read. Sockets shield the programmer from low-level details of the network, such as error detection, packet sizes, packet splitting, packet retransmission, network addresses, and more.

Setting ________________ to true ensures that packets are sent as quickly as possible regardless of their size.

TCP_NODELAY

Socket options specify how the native sockets on which the Java Socket class relies send and receive data. Java supports nine options for client-side sockets:

TCP_NODELAY SO_BINDADDR SO_TIMEOUT SO_LINGER SO_SNDBUF SO_RCVBUF SO_KEEPALIVE OOBINLINE IP_TOS

The close() method shuts down both input and output from the socket. On occasion, you may want to shut down only half of the connection, either input or output. How is this achieved?

The shutdownInput() and shutdownOutput() methods close only half the connection. *The isInputShutdown() and isOutputShutdown() methods tell you whether the input and output streams are open or closed

How is a local port determined?

Unlike the remote port, which (for a client socket) is usually a "well-known port" that has been preassigned by a standards committee, the local port is usually chosen by the system at runtime from the available unused ports. This way, many different clients on a system can access the same service at the same time. The local port is embedded in outbound IP packets along with the local host's IP address, so the server can send data back to the right port on the client.

Data is transmitted across the Internet in packets of finite size called ____________.

datagrams Each datagram contains a header and a payload. The header contains the address and port to which the packet is going, the address and port from which the packet came, a checksum to detect data corruption, and various other housekeeping information used to ensure reliable transmission. The payload contains the data itself.

The __________ method tells you whether the socket successfully bound to the outgoing port on the local system.

isBound()

The ________________ method returns true if the socket is closed, false if it isn't.

isClosed()

The ______________ method tells you whether the socket has ever been connected to a remote host.

isConnected() *If the socket was able to connect to the remote host at all, this method returns true, even after that socket has been closed. To tell if a socket is currently open, you need to check that isConnected() returns true and isClosed() returns false.

Constructor to create an unconnected socket that connects through a specified proxy server:

public Socket(Proxy proxy) *SOCKS is the only low-level proxy type Java understands.


Kaugnay na mga set ng pag-aaral

WGU C211: Additional Study - 3rd Attempt OA Quizzes

View Set

AIC 300 - Claims in an Evolving World

View Set

Connaissez-vous ces mots de la langue soutenue ? Vocabulaire n°2

View Set

MGSC 346: ch 4 Supplement B Waiting Lines

View Set

1. Epiphany from Children - Part 1

View Set

Pathophysiology: Chapter 21 Congenital and Genetic Disorders

View Set