public class IpClient
extends java.lang.Object
implements java.lang.AutoCloseable
Example usage:
try { // create new IpClient instance with hostname, port and timeout arguments IpClient client = new IpClient("10.0.0.1",53,5000); // establish connection with server client.connect(); // obtain OutputStream for sending data to server OutputStream out = client.getOutputStream(); // obtain InputStream for reading data from server InputStream in = client.getInputStream(); // disconnect from server client.disconnect(); } catch(IpClientException ipe) { ipe.printStackTrace(); }
Constructor and Description |
---|
IpClient(java.lang.String hostname,
int port)
Creates a new IpClient instance.
|
IpClient(java.lang.String hostname,
int port,
int timeout)
Creates a new IpClient instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addIpClientListener(IpClientListener listener)
Adds IpClient event listener.
|
void |
clearProxySettings()
Clears proxy server values.
|
void |
close() |
IpClient |
connect()
Establishes connection with server.
|
void |
disconnect()
Closes connection with server.
|
int |
getConnectTimeout()
Gets the timeout used when opening a server connection.
|
java.io.InputStream |
getInputStream()
Gets InputStream from socket connection established with server.
|
java.io.OutputStream |
getOutputStream()
Gets OutputStream from socket connection established with server.
|
int |
getReadTimeout()
Gets the timeout used when reading responses from server.
|
java.net.Socket |
getSocket()
Gets Socket established after invoking the IpClient#connect method.
|
void |
removeIpClientListener(IpClientListener listener)
Removes an IpClient event listener.
|
void |
setConnectTimeout(int timeout)
Sets the timeout for opening a server connection.
|
void |
setInputStream(java.io.InputStream input)
Replaces InputStream from socket connection established with server.
|
void |
setOutputStream(java.io.OutputStream output)
Sets OutputStream from socket connection established with server.
|
void |
setProxyAuthentication(java.lang.String proxyUsername,
java.lang.String proxyPassword)
Sets the username and password to use when for authentication with
proxy server.
|
void |
setProxyHost(java.lang.String proxyHostname,
int proxyPort)
Sets the proxy hostname and port for this connection.
|
void |
setProxyType(java.lang.String proxyType)
Sets the proxy type will be used for this connection.
|
void |
setReadTimeout(int timeout)
Sets the timeout for reading responses from server.
|
void |
setSocket(java.net.Socket socket)
Sets socket replacing current socket with new socket.
|
public IpClient(java.lang.String hostname, int port)
hostname
- the server hostname or IP addressport
- the server portpublic IpClient(java.lang.String hostname, int port, int timeout)
hostname
- the server hostname or IP addressport
- the server porttimeout
- the timeout for establishing a connection specified in ms (milliseconds)public void setConnectTimeout(int timeout)
timeout
- the timeout in millisecondspublic int getConnectTimeout()
public void setInputStream(java.io.InputStream input)
input
- The input stream instancepublic java.io.InputStream getInputStream()
public void setOutputStream(java.io.OutputStream output)
output
- The output stream instancepublic java.io.OutputStream getOutputStream()
public void setReadTimeout(int timeout)
timeout
- the timeout in millisecondspublic int getReadTimeout()
public void setSocket(java.net.Socket socket) throws IpClientException
socket
- the new socketIpClientException
- if a I/O error occurs.public java.net.Socket getSocket()
connect()
public void setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)
#clearProxySettings
method.proxyUsername
- the proxy usernameproxyPassword
- the proxy passwordclearProxySettings()
public void setProxyHost(java.lang.String proxyHostname, int proxyPort)
#clearProxySettings
method.proxyHostname
- the hostname or ip address of the proxy serverproxyPort
- the port of the proxy serverclearProxySettings()
public void setProxyType(java.lang.String proxyType)
proxyType
- The proxy type. Valid values: HTTP, SOCKS5public void clearProxySettings()
public void addIpClientListener(IpClientListener listener)
listener
- an IpClientListenerpublic IpClient connect() throws IpClientException
IpClientException
- if an I/O or network related error occurspublic void disconnect() throws IpClientException
IpClientException
- if an I/O or network related error occurspublic void close() throws java.lang.Exception
close
in interface java.lang.AutoCloseable
java.lang.Exception
public void removeIpClientListener(IpClientListener listener)
listener
- an IpClientListenerCopyright © JSCAPE LLC. 1999-2021. All Rights Reserved