Package com.ibm.di.api.remote.impl.rmi
Class SocketWrapper
- java.lang.Object
-
- java.net.Socket
-
- com.ibm.di.api.remote.impl.rmi.SocketWrapper
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class SocketWrapper extends java.net.SocketA wrapper class of Socket class for use by the RMI. Socket class implements client sockets. A socket is an endpoint for communication between two machines.
-
-
Constructor Summary
Constructors Constructor Description SocketWrapper(java.net.Socket aSocket)Creates SocketWrapper by givenSocket.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind(java.net.SocketAddress aBindpoint)Binds the socket to a local address.voidclose()Closes this socket.voidconnect(java.net.SocketAddress aEndpoint)Connects this socket to the server.voidconnect(java.net.SocketAddress aEndpoint, int aTimeout)Connects this socket to the server with a specified timeout value.java.nio.channels.SocketChannelgetChannel()Returns the unique SocketChannel object associated with this socket, if any.java.net.InetAddressgetInetAddress()Returns the address to which the socket is connected.java.io.InputStreamgetInputStream()Returns anInputStreamWrapperfor this socket.booleangetKeepAlive()Tests if SO_KEEPALIVE is enabled.java.net.InetAddressgetLocalAddress()Gets the local address to which the socket is bound.intgetLocalPort()Returns the local port to which this socket is bound.java.net.SocketAddressgetLocalSocketAddress()Returns the address of the endpoint this socket is bound to, or null if it is not bound yetbooleangetOOBInline()Tests if OOBINLINE is enabled.java.io.OutputStreamgetOutputStream()Returns an output stream for this socket.intgetPort()Returns the remote port to which this socket is connected.intgetReceiveBufferSize()Gets the value of the SO_RCVBUF option for this Socket, that is the buffer size used by the platform for input on this Socket.java.net.SocketAddressgetRemoteSocketAddress()Returns the address of the endpoint this socket is connected to, or null if it is unconnected.booleangetReuseAddress()Tests if SO_REUSEADDR is enabled.intgetSendBufferSize()Get value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket.intgetSoLinger()Returns setting for SO_LINGER.intgetSoTimeout()Returns setting for SO_TIMEOUT.booleangetTcpNoDelay()Tests if TCP_NODELAY is enabled.intgetTrafficClass()Gets traffic class or type-of-service in the IP header for packets sent from this SocketbooleanisBound()Returns the binding state of the socket.booleanisClosed()Returns the closed state of the socket.booleanisConnected()Returns the connection state of the socket.booleanisInputShutdown()Returns whether the read-half of the socket connection is closed.booleanisOutputShutdown()Returns whether the write-half of the socket connection is closed.voidsendUrgentData(int aData)Send one byte of urgent data on the socket.voidsetKeepAlive(boolean aOn)Enable/disable SO_KEEPALIVE.voidsetOOBInline(boolean aOn)Enable/disable OOBINLINE (receipt of TCP urgent data) By default, this option is disabled and TCP urgent data received on a socket is silently discarded.voidsetReceiveBufferSize(int aSize)Sets the SO_RCVBUF option to the specified value for this Socket.voidsetReuseAddress(boolean aOn)Enable/disable the SO_REUSEADDR socket option.voidsetSendBufferSize(int aSize)Sets the SO_SNDBUF option to the specified value for this Socket.voidsetSoLinger(boolean aOn, int aLinger)Enable/disable SO_LINGER with the specified linger time in seconds.voidsetSoTimeout(int aTimeout)Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.voidsetTcpNoDelay(boolean aOn)Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).voidsetTrafficClass(int aTc)Sets traffic class or type-of-service octet in the IP header for packets sent from this Socket.voidshutdownInput()Places the input stream for this socket at "end of stream".voidshutdownOutput()Disables the output stream for this socket.java.lang.StringtoString()Converts this socket to a String.
-
-
-
Method Detail
-
connect
public void connect(java.net.SocketAddress aEndpoint) throws java.io.IOExceptionConnects this socket to the server.- Overrides:
connectin classjava.net.Socket- Parameters:
aEndpoint- theSocketAddress- Throws:
java.io.IOException- if an error occurs during the connection
-
connect
public void connect(java.net.SocketAddress aEndpoint, int aTimeout) throws java.io.IOExceptionConnects this socket to the server with a specified timeout value. A timeout of zero is interpreted as an infinite timeout. The connection will then block until established or an error occurs.- Overrides:
connectin classjava.net.Socket- Parameters:
aEndpoint- theSocketAddressaTimeout- the timeout value to be used in milliseconds.- Throws:
java.io.IOException- if an error occurs during the connection
-
bind
public void bind(java.net.SocketAddress aBindpoint) throws java.io.IOExceptionBinds the socket to a local address.If the address is null, then the system will pick up an ephemeral port and a valid local address to bind the socket.
- Overrides:
bindin classjava.net.Socket- Parameters:
aBindpoint- theSocketAddressto bind to- Throws:
java.io.IOException
-
getInetAddress
public java.net.InetAddress getInetAddress()
Returns the address to which the socket is connected.- Overrides:
getInetAddressin classjava.net.Socket- Returns:
- the remote IP address to which this socket is connected, or
nullif the socket is not connected.
-
getLocalAddress
public java.net.InetAddress getLocalAddress()
Gets the local address to which the socket is bound.- Overrides:
getLocalAddressin classjava.net.Socket- Returns:
- the local address to which the socket is bound or
InetAddress.anyLocalAddress()if the socket is not bound yet
-
getPort
public int getPort()
Returns the remote port to which this socket is connected.- Overrides:
getPortin classjava.net.Socket- Returns:
- the remote port number to which this socket is connected, or 0 if the socket is not connected yet
-
getLocalPort
public int getLocalPort()
Returns the local port to which this socket is bound.- Overrides:
getLocalPortin classjava.net.Socket- Returns:
- the local port number to which this socket is bound or -1 if the socket is not bound yet
-
getRemoteSocketAddress
public java.net.SocketAddress getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, or null if it is unconnected.- Overrides:
getRemoteSocketAddressin classjava.net.Socket- Returns:
- a
SocketAddressreprensenting the remote endpoint of this socket, or null if it is not connected yet - See Also:
getInetAddress(),connect(SocketAddress)
-
getLocalSocketAddress
public java.net.SocketAddress getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to, or null if it is not bound yet- Overrides:
getLocalSocketAddressin classjava.net.Socket- Returns:
- a
SocketAddressrepresenting the local endpoint of this socket, or null if it is not bound yet - See Also:
getLocalAddress(),bind(SocketAddress)
-
getChannel
public java.nio.channels.SocketChannel getChannel()
Returns the unique SocketChannel object associated with this socket, if any.- Overrides:
getChannelin classjava.net.Socket- Returns:
- the socket channel associated with this socket, or
nullif this socket was not created for a channel
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOExceptionReturns anInputStreamWrapperfor this socket.- Overrides:
getInputStreamin classjava.net.Socket- Returns:
- an
InputStreamWrapperfor reading bytes from this socket - Throws:
java.io.IOException- if an I/O error occurs when creating the input stream, the socket is closed, the socket is not connected, or the socket input has been shutdown usingshutdownInput()
-
getOutputStream
public java.io.OutputStream getOutputStream() throws java.io.IOExceptionReturns an output stream for this socket.- Overrides:
getOutputStreamin classjava.net.Socket- Returns:
- an output stream for writing bytes to this socket
- Throws:
java.io.IOException- if an I/O error occurs when creating the output stream or if the socket is not connected
-
setTcpNoDelay
public void setTcpNoDelay(boolean aOn) throws java.net.SocketExceptionEnable/disable TCP_NODELAY (disable/enable Nagle's algorithm).- Overrides:
setTcpNoDelayin classjava.net.Socket- Parameters:
aOn-trueto enable TCP_NODELAY,falseto disable.- Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error.
-
getTcpNoDelay
public boolean getTcpNoDelay() throws java.net.SocketExceptionTests if TCP_NODELAY is enabled.- Overrides:
getTcpNoDelayin classjava.net.Socket- Returns:
- a
booleanindicating whether or not TCP_NODELAY is enabled. - Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error.
-
setSoLinger
public void setSoLinger(boolean aOn, int aLinger) throws java.net.SocketExceptionEnable/disable SO_LINGER with the specified linger time in seconds. The maximum timeout value is platform specific. The setting only affects socket close.- Overrides:
setSoLingerin classjava.net.Socket- Parameters:
aOn- whether or not to linger onaLinger- how long to linger for, if on is true- Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error
-
getSoLinger
public int getSoLinger() throws java.net.SocketExceptionReturns setting for SO_LINGER. -1 returns implies that the option is disabled. The setting only affects socket close.- Overrides:
getSoLingerin classjava.net.Socket- Returns:
- the setting for SO_LINGER.
- Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error
-
sendUrgentData
public void sendUrgentData(int aData) throws java.io.IOExceptionSend one byte of urgent data on the socket. The byte to be sent is the lowest eight bits of the data parameter. The urgent byte is sent after any preceding writes to the socket OutputStream and before any future writes to the OutputStream.- Overrides:
sendUrgentDatain classjava.net.Socket- Parameters:
aData- The byte of data to send- Throws:
java.io.IOException- if there is an error sending the data.
-
setOOBInline
public void setOOBInline(boolean aOn) throws java.net.SocketExceptionEnable/disable OOBINLINE (receipt of TCP urgent data) By default, this option is disabled and TCP urgent data received on a socket is silently discarded.- Overrides:
setOOBInlinein classjava.net.Socket- Parameters:
aOn-trueto enable OOBINLINE, false to disable.- Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error.
-
getOOBInline
public boolean getOOBInline() throws java.net.SocketExceptionTests if OOBINLINE is enabled.- Overrides:
getOOBInlinein classjava.net.Socket- Returns:
- a
booleanindicating whether or not OOBINLINE is enabled. - Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error.
-
setSoTimeout
public void setSoTimeout(int aTimeout) throws java.net.SocketExceptionEnable/disable SO_TIMEOUT with the specified timeout, in milliseconds.- Overrides:
setSoTimeoutin classjava.net.Socket- Parameters:
aTimeout- the specified timeout, in milliseconds.- Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error.- See Also:
getSoTimeout()
-
getSoTimeout
public int getSoTimeout() throws java.net.SocketExceptionReturns setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).- Overrides:
getSoTimeoutin classjava.net.Socket- Returns:
- the setting for SO_TIMEOUT
- Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error.- See Also:
setSoTimeout(int)
-
setSendBufferSize
public void setSendBufferSize(int aSize) throws java.net.SocketExceptionSets the SO_SNDBUF option to the specified value for this Socket.- Overrides:
setSendBufferSizein classjava.net.Socket- Parameters:
aSize- the size to which to set the send buffer size. This value must be greater than 0.- Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error.- See Also:
getSendBufferSize()
-
getSendBufferSize
public int getSendBufferSize() throws java.net.SocketExceptionGet value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket.- Overrides:
getSendBufferSizein classjava.net.Socket- Returns:
- the value of the SO_SNDBUF option for this Socket.
- Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error.- See Also:
setSendBufferSize(int)
-
setReceiveBufferSize
public void setReceiveBufferSize(int aSize) throws java.net.SocketExceptionSets the SO_RCVBUF option to the specified value for this Socket.- Overrides:
setReceiveBufferSizein classjava.net.Socket- Parameters:
aSize- the size to which to set the receive buffer size. This value must be greater than 0.- Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error.- See Also:
getReceiveBufferSize()
-
getReceiveBufferSize
public int getReceiveBufferSize() throws java.net.SocketExceptionGets the value of the SO_RCVBUF option for this Socket, that is the buffer size used by the platform for input on this Socket.- Overrides:
getReceiveBufferSizein classjava.net.Socket- Returns:
- the value of the SO_RCVBUF option for this Socket.
- Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error.- See Also:
setReceiveBufferSize(int)
-
setKeepAlive
public void setKeepAlive(boolean aOn) throws java.net.SocketExceptionEnable/disable SO_KEEPALIVE.- Overrides:
setKeepAlivein classjava.net.Socket- Parameters:
aOn- whether or not to have socket keep alive turned on.- Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error.- See Also:
getKeepAlive()
-
getKeepAlive
public boolean getKeepAlive() throws java.net.SocketExceptionTests if SO_KEEPALIVE is enabled.- Overrides:
getKeepAlivein classjava.net.Socket- Returns:
- a
booleanindicating whether or not SO_KEEPALIVE is enabled. - Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error.- See Also:
setKeepAlive(boolean)
-
setTrafficClass
public void setTrafficClass(int aTc) throws java.net.SocketExceptionSets traffic class or type-of-service octet in the IP header for packets sent from this Socket.- Overrides:
setTrafficClassin classjava.net.Socket- Parameters:
aTc- anintvalue for the bitset.- Throws:
java.net.SocketException- if there is an error setting the traffic class or type-of-service- See Also:
getTrafficClass()
-
getTrafficClass
public int getTrafficClass() throws java.net.SocketExceptionGets traffic class or type-of-service in the IP header for packets sent from this Socket- Overrides:
getTrafficClassin classjava.net.Socket- Returns:
- the traffic class or type-of-service already set
- Throws:
java.net.SocketException- if there is an error obtaining the traffic class or type-of-service value.- See Also:
setTrafficClass(int)
-
setReuseAddress
public void setReuseAddress(boolean aOn) throws java.net.SocketExceptionEnable/disable the SO_REUSEADDR socket option.- Overrides:
setReuseAddressin classjava.net.Socket- Parameters:
aOn- whether to enable or disable the socket option- Throws:
java.net.SocketException- if an error occurs enabling or disabling the SO_RESUEADDR socket option, or the socket is closed.- See Also:
getReuseAddress()
-
getReuseAddress
public boolean getReuseAddress() throws java.net.SocketExceptionTests if SO_REUSEADDR is enabled.- Overrides:
getReuseAddressin classjava.net.Socket- Returns:
- a
booleanindicating whether or not SO_REUSEADDR is enabled. - Throws:
java.net.SocketException- if there is an error in the underlying protocol, such as a TCP error.- See Also:
setReuseAddress(boolean)
-
close
public void close() throws java.io.IOExceptionCloses this socket.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.net.Socket- Throws:
java.io.IOException- if an I/O error occurs when closing this socket.
-
shutdownInput
public void shutdownInput() throws java.io.IOExceptionPlaces the input stream for this socket at "end of stream". Any data sent to the input stream side of the socket is acknowledged and then silently discarded.- Overrides:
shutdownInputin classjava.net.Socket- Throws:
java.io.IOException- if an I/O error occurs when shutting down this socket.
-
shutdownOutput
public void shutdownOutput() throws java.io.IOExceptionDisables the output stream for this socket. For a TCP socket, any previously written data will be sent followed by TCP's normal connection termination sequence. If you write to a socket output stream after invoking shutdownOutput() on the socket, the stream will throw an IOException.- Overrides:
shutdownOutputin classjava.net.Socket- Throws:
java.io.IOException- if an I/O error occurs when shutting down this socket.
-
toString
public java.lang.String toString()
Converts this socket to a String.- Overrides:
toStringin classjava.net.Socket- Returns:
- string representation of this socket.
-
isConnected
public boolean isConnected()
Returns the connection state of the socket.- Overrides:
isConnectedin classjava.net.Socket- Returns:
trueif the socket successfuly connected to a server
-
isBound
public boolean isBound()
Returns the binding state of the socket.- Overrides:
isBoundin classjava.net.Socket- Returns:
trueif the socket successfuly bound to an address
-
isClosed
public boolean isClosed()
Returns the closed state of the socket.- Overrides:
isClosedin classjava.net.Socket- Returns:
trueif the socket has been closed- See Also:
close()
-
isInputShutdown
public boolean isInputShutdown()
Returns whether the read-half of the socket connection is closed.- Overrides:
isInputShutdownin classjava.net.Socket- Returns:
trueif the input of the socket has been shutdown- See Also:
shutdownInput()
-
isOutputShutdown
public boolean isOutputShutdown()
Returns whether the write-half of the socket connection is closed.- Overrides:
isOutputShutdownin classjava.net.Socket- Returns:
trueif the output of the socket has been shutdown
-
-