APIdia Launch Partner
Top Description Fields Constructors Methods
sun.net

public Class NetworkClient

extends Object
Class Inheritance
Known Direct Subclasses
sun.net.TransferProtocolClient, sun.net.www.http.HttpClient
Imports
java.io.*, java.net.Socket, .InetAddress, .InetSocketAddress, .Proxy, java.util.Arrays

This is the base class for network clients.
Author
Jonathan Payne

Field Summary

Modifier and TypeField and Description
protected int
public static final int
public static final int
protected static int
protected static int
protected static String
protected Proxy
protected int
public InputStream
serverInput

Buffered stream for reading replies from server.

public PrintStream
serverOutput

Stream for printing to the server.

protected Socket
serverSocket

Socket for communicating with server.

Constructor Summary

AccessConstructor and Description
public
NetworkClient(String host, int port)

Create connection with host host on port port

public

Method Summary

Modifier and TypeMethod and Description
public void
closeServer()

Close an open connection to the server.

protected Socket
createSocket()

The following method, createSocket, is provided to allow the https client to override it so that it may use its socket factory to create the socket.

protected Socket
doConnect(String server, int port)

Return a socket connected to the server, with any appropriate options pre-established

public int
protected InetAddress
public int
private static boolean
isASCIISuperset(String encoding)

Test the named character encoding to verify that it converts ASCII characters correctly.

public void
openServer(String server, int port)

Open a connection to the server.

public boolean
serverIsOpen()

Return server connection status

public void
setConnectTimeout(int timeout)

public void
setReadTimeout(int timeout)

Sets the read timeout.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectTimeoutback to summary
protected int connectTimeout
DEFAULT_CONNECT_TIMEOUTback to summary
public static final int DEFAULT_CONNECT_TIMEOUT
DEFAULT_READ_TIMEOUTback to summary
public static final int DEFAULT_READ_TIMEOUT
defaultConnectTimeoutback to summary
protected static int defaultConnectTimeout
defaultSoTimeoutback to summary
protected static int defaultSoTimeout
encodingback to summary
protected static String encoding
proxyback to summary
protected Proxy proxy
readTimeoutback to summary
protected int readTimeout
serverInputback to summary
public InputStream serverInput

Buffered stream for reading replies from server.

serverOutputback to summary
public PrintStream serverOutput

Stream for printing to the server.

serverSocketback to summary
protected Socket serverSocket

Socket for communicating with server.

Constructor Detail

NetworkClientback to summary
public NetworkClient(String host, int port) throws IOException

Create connection with host host on port port

Annotations
@SuppressWarnings:this-escape
NetworkClientback to summary
public NetworkClient()

Method Detail

closeServerback to summary
public void closeServer() throws IOException

Close an open connection to the server.

createSocketback to summary
protected Socket createSocket() throws IOException

The following method, createSocket, is provided to allow the https client to override it so that it may use its socket factory to create the socket.

doConnectback to summary
protected Socket doConnect(String server, int port) throws IOException

Return a socket connected to the server, with any appropriate options pre-established

getConnectTimeoutback to summary
public int getConnectTimeout()
getLocalAddressback to summary
protected InetAddress getLocalAddress() throws IOException
getReadTimeoutback to summary
public int getReadTimeout()
isASCIISupersetback to summary
private static boolean isASCIISuperset(String encoding) throws Exception

Test the named character encoding to verify that it converts ASCII characters correctly. We have to use an ASCII based encoding, or else the NetworkClients will not work correctly in EBCDIC based systems. However, we cannot just use ASCII or ISO8859_1 universally, because in Asian locales, non-ASCII characters may be embedded in otherwise ASCII based protocols (e.g. HTTP). The specifications (RFC2616, 2398) are a little ambiguous in this matter. For instance, RFC2398 [part 2.1] says that the HTTP request URI should be escaped using a defined mechanism, but there is no way to specify in the escaped string what the original character set is. It is not correct to assume that UTF-8 is always used (as in URLs in HTML 4.0). For this reason, until the specifications are updated to deal with this issue more comprehensively, and more importantly, HTTP servers are known to support these mechanisms, we will maintain the current behavior where it is possible to send non-ASCII characters in their original unescaped form.

openServerback to summary
public void openServer(String server, int port) throws IOException

Open a connection to the server.

serverIsOpenback to summary
public boolean serverIsOpen()

Return server connection status

setConnectTimeoutback to summary
public void setConnectTimeout(int timeout)
setReadTimeoutback to summary
public void setReadTimeout(int timeout)

Sets the read timeout.

Note

Public URLConnection (and protocol specific implementations) protect against negative timeout values being set. This implementation, and protocol specific implementations, use -1 to represent the default read timeout. This method may be invoked with the default timeout value when the protocol handler is trying to reset the timeout after doing a potentially blocking internal operation, e.g. cleaning up unread response data, buffering error stream response data, etc