Package sun.net
Class NetworkClient
- java.lang.Object
-
- sun.net.NetworkClient
-
- Direct Known Subclasses:
HttpClient
public class NetworkClient extends Object
This is the base class for network clients.
-
-
Field Summary
Fields Modifier and Type Field Description protected intconnectTimeoutstatic intDEFAULT_CONNECT_TIMEOUTstatic intDEFAULT_READ_TIMEOUTprotected static intdefaultConnectTimeoutprotected static intdefaultSoTimeoutprotected static Stringencodingprotected intreadTimeoutInputStreamserverInputBuffered stream for reading replies from server.PrintStreamserverOutputStream for printing to the server.protected SocketserverSocketSocket for communicating with server.
-
Constructor Summary
Constructors Constructor Description NetworkClient()NetworkClient(String host, int port)Create connection with host host on port port
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseServer()Close an open connection to the server.protected SocketcreateSocket()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 SocketdoConnect(String server, int port)Return a socket connected to the server, with any appropriate options pre-establishedintgetConnectTimeout()intgetReadTimeout()voidopenServer(String server, int port)Open a connection to the server.booleanserverIsOpen()Return server connection statusvoidsetConnectTimeout(int timeout)voidsetReadTimeout(int timeout)Sets the read timeout.
-
-
-
Field Detail
-
DEFAULT_READ_TIMEOUT
public static final int DEFAULT_READ_TIMEOUT
- See Also:
- Constant Field Values
-
DEFAULT_CONNECT_TIMEOUT
public static final int DEFAULT_CONNECT_TIMEOUT
- See Also:
- Constant Field Values
-
serverOutput
@Nullable public PrintStream serverOutput
Stream for printing to the server.
-
serverInput
@Nullable public InputStream serverInput
Buffered stream for reading replies from server.
-
defaultSoTimeout
protected static int defaultSoTimeout
-
defaultConnectTimeout
protected static int defaultConnectTimeout
-
readTimeout
protected int readTimeout
-
connectTimeout
protected int connectTimeout
-
encoding
protected static String encoding
-
-
Constructor Detail
-
NetworkClient
public NetworkClient(String host, int port) throws IOException
Create connection with host host on port port- Throws:
IOException
-
NetworkClient
public NetworkClient()
-
-
Method Detail
-
openServer
public void openServer(String server, int port) throws IOException, UnknownHostException
Open a connection to the server.- Throws:
IOExceptionUnknownHostException
-
doConnect
protected Socket doConnect(String server, int port) throws IOException, UnknownHostException
Return a socket connected to the server, with any appropriate options pre-established- Throws:
IOExceptionUnknownHostException
-
createSocket
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.- Throws:
IOException
-
closeServer
public void closeServer() throws IOExceptionClose an open connection to the server.- Throws:
IOException
-
serverIsOpen
public boolean serverIsOpen()
Return server connection status
-
setConnectTimeout
public void setConnectTimeout(int timeout)
-
getConnectTimeout
public int getConnectTimeout()
-
setReadTimeout
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
-
getReadTimeout
public int getReadTimeout()
-
-