de.unkrig.commons.net
Class TcpClient
java.lang.Object
de.unkrig.commons.net.TcpClient
- All Implemented Interfaces:
- java.io.Closeable
public final class TcpClient
- extends java.lang.Object
- implements java.io.Closeable
A very thin wrapper around Socket.Socket(InetAddress, int).
Adds a data logging facility, and has idempotent getInputStream() and getOutputStream()
methods (as opposed to Socket).
Data logging is enabled by setting the level of logger de.unkrig.commons.net.TcpClient to Level.FINEST or higher.
- See Also:
TcpClient(InetAddress, int)
|
Constructor Summary |
TcpClient(java.net.InetAddress address,
int port)
Connects to the given address and port. |
TcpClient(java.lang.String host,
int port)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TcpClient
public TcpClient(java.lang.String host,
int port)
throws java.io.IOException
- Throws:
java.io.IOException- See Also:
TcpClient(InetAddress, int)
TcpClient
public TcpClient(java.net.InetAddress address,
int port)
throws java.io.IOException
- Connects to the given
address and port. Data can be sent to the remote server through the
OutputStream returned by getOutputStream(), and data can be read from the remote server
through the InputStream returned by getInputStream().
- Throws:
java.io.IOException
getInputStream
public java.io.InputStream getInputStream()
- Returns:
- The stream from the server
getOutputStream
public java.io.OutputStream getOutputStream()
- Returns:
- The stream to the server
close
public void close()
throws java.io.IOException
- Specified by:
close in interface java.io.Closeable
- Throws:
java.io.IOException
getRemoteSocketAddress
public java.net.SocketAddress getRemoteSocketAddress()
- Returns:
- The address of the server socket that this client is connected to