public class ReliableSocket
extends java.net.Socket
Socket
Modifier and Type | Field and Description |
---|---|
static boolean |
DEBUG |
static java.util.logging.Logger |
LOGGER |
Constructor and Description |
---|
ReliableSocket()
Creates an unconnected RUDP socket with default RUDP parameters.
|
ReliableSocket(java.net.InetAddress address,
int port,
java.net.InetAddress localAddr,
int localPort)
Creates a RUDP socket and connects it to the specified remote address on
the specified remote port.
|
ReliableSocket(ReliableSocketProfile profile)
Creates an unconnected RUDP socket and uses the given RUDP parameters.
|
ReliableSocket(java.lang.String host,
int port)
Creates a RUDP socket and connects it to the specified port number on the
named host.
|
ReliableSocket(java.lang.String host,
int port,
java.net.InetAddress localAddr,
int localPort)
Creates a RUDP socket and connects it to the specified remote host on the
specified remote port.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(ReliableSocketListener listener)
Adds the specified listener to this socket.
|
void |
addStateListener(ReliableSocketStateListener stateListener)
Adds the specified state listener to this socket.
|
void |
bind(java.net.SocketAddress bindpoint) |
void |
close() |
void |
connect(java.net.SocketAddress endpoint) |
void |
connect(java.net.SocketAddress endpoint,
int timeout) |
java.nio.channels.SocketChannel |
getChannel() |
java.net.InetAddress |
getInetAddress() |
java.io.InputStream |
getInputStream() |
boolean |
getKeepAlive() |
java.net.InetAddress |
getLocalAddress() |
int |
getLocalPort() |
java.net.SocketAddress |
getLocalSocketAddress() |
java.io.OutputStream |
getOutputStream() |
int |
getPort() |
int |
getReceiveBufferSize() |
java.net.SocketAddress |
getRemoteSocketAddress() |
static java.util.concurrent.ScheduledThreadPoolExecutor |
getScheduledThreadPoolExecutor() |
int |
getSendBufferSize() |
boolean |
getTcpNoDelay() |
boolean |
isBound() |
boolean |
isClosed() |
boolean |
isConnected() |
boolean |
isInputShutdown() |
boolean |
isOutputShutdown() |
void |
removeListener(ReliableSocketListener listener)
Removes the specified listener from this socket.
|
void |
removeStateListener(ReliableSocketStateListener stateListener)
Removes the specified state listener from this socket.
|
void |
reset()
Resets the socket state.
|
void |
reset(ReliableSocketProfile profile)
Resets the socket state and profile.
|
void |
setKeepAlive(boolean on) |
void |
setReceiveBufferSize(int size) |
void |
setSendBufferSize(int size) |
void |
setSoTimeout(int timeout) |
void |
setTcpNoDelay(boolean on) |
void |
setUUID(java.util.UUID uuid) |
void |
shutdownInput() |
void |
shutdownOutput() |
public static final boolean DEBUG
public static final java.util.logging.Logger LOGGER
public ReliableSocket() throws java.io.IOException
java.io.IOException
- if an I/O error occurs when creating the underlying UDP
socket.public ReliableSocket(ReliableSocketProfile profile) throws java.io.IOException
java.io.IOException
- if an I/O error occurs when creating the underlying UDP
socket.public ReliableSocket(java.lang.String host, int port) throws java.net.UnknownHostException, java.io.IOException
If the specified host is null it is the equivalent of specifying
the address as
InetAddress.getByName
(null)
. In other words, it is equivalent to specifying an address of the
loopback interface.
host
- the host name, or null
for the loopback address.port
- the port number.java.net.UnknownHostException
- if the IP address of the host could not be determined.java.io.IOException
- if an I/O error occurs when creating the socket.java.lang.IllegalArgumentException
- if the port parameter is outside the specified range of valid
port values, which is between 0 and 65535, inclusive.Socket.Socket(String, int)
public ReliableSocket(java.net.InetAddress address, int port, java.net.InetAddress localAddr, int localPort) throws java.io.IOException
If the specified local address is null it is the equivalent of
specifying the address as the wildcard address (see
InetAddress.isAnyLocalAddress
()
).
A local port number of zero
will let the system pick up a
free port in the bind
operation.
address
- the remote address.port
- the remote port.localAddr
- the local address the socket is bound to, or null
for the wildcard address.localPort
- the local port the socket is bound to, or zero
for a system selected free port.java.io.IOException
- if an I/O error occurs when creating the socket.java.lang.IllegalArgumentException
- if the port parameter is outside the specified range of valid
port values, which is between 0 and 65535, inclusive.public ReliableSocket(java.lang.String host, int port, java.net.InetAddress localAddr, int localPort) throws java.io.IOException
If the specified host is null it is the equivalent of specifying
the address as
InetAddress.getByName
(null)
. In other words, it is equivalent to specifying an address of the
loopback interface.
A local port number of zero
will let the system pick up a
free port in the bind
operation.
host
- the name of the remote host, or null
for the
loopback address.port
- the remote port.localAddr
- the local address the socket is bound to, or null
for the wildcard address.localPort
- the local port the socket is bound to, or zero
for a system selected free port.java.io.IOException
- if an I/O error occurs when creating the socket.java.lang.IllegalArgumentException
- if the port parameter is outside the specified range of valid
port values, which is between 0 and 65535, inclusive.public void bind(java.net.SocketAddress bindpoint) throws java.io.IOException
bind
in class java.net.Socket
java.io.IOException
public void connect(java.net.SocketAddress endpoint) throws java.io.IOException
connect
in class java.net.Socket
java.io.IOException
public void connect(java.net.SocketAddress endpoint, int timeout) throws java.io.IOException
connect
in class java.net.Socket
java.io.IOException
public java.nio.channels.SocketChannel getChannel()
getChannel
in class java.net.Socket
public java.net.InetAddress getInetAddress()
getInetAddress
in class java.net.Socket
public int getPort()
getPort
in class java.net.Socket
public java.net.SocketAddress getRemoteSocketAddress()
getRemoteSocketAddress
in class java.net.Socket
public java.net.InetAddress getLocalAddress()
getLocalAddress
in class java.net.Socket
public int getLocalPort()
getLocalPort
in class java.net.Socket
public java.net.SocketAddress getLocalSocketAddress()
getLocalSocketAddress
in class java.net.Socket
public java.io.InputStream getInputStream() throws java.io.IOException
getInputStream
in class java.net.Socket
java.io.IOException
public java.io.OutputStream getOutputStream() throws java.io.IOException
getOutputStream
in class java.net.Socket
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.net.Socket
java.io.IOException
public boolean isBound()
isBound
in class java.net.Socket
public boolean isConnected()
isConnected
in class java.net.Socket
public boolean isClosed()
isClosed
in class java.net.Socket
public void setUUID(java.util.UUID uuid)
public void setSoTimeout(int timeout) throws java.net.SocketException
setSoTimeout
in class java.net.Socket
java.net.SocketException
public void setSendBufferSize(int size) throws java.net.SocketException
setSendBufferSize
in class java.net.Socket
java.net.SocketException
public int getSendBufferSize() throws java.net.SocketException
getSendBufferSize
in class java.net.Socket
java.net.SocketException
public void setReceiveBufferSize(int size) throws java.net.SocketException
setReceiveBufferSize
in class java.net.Socket
java.net.SocketException
public int getReceiveBufferSize() throws java.net.SocketException
getReceiveBufferSize
in class java.net.Socket
java.net.SocketException
public void setTcpNoDelay(boolean on) throws java.net.SocketException
setTcpNoDelay
in class java.net.Socket
java.net.SocketException
public boolean getTcpNoDelay()
getTcpNoDelay
in class java.net.Socket
public void setKeepAlive(boolean on) throws java.net.SocketException
setKeepAlive
in class java.net.Socket
java.net.SocketException
public boolean getKeepAlive() throws java.net.SocketException
getKeepAlive
in class java.net.Socket
java.net.SocketException
public void shutdownInput() throws java.io.IOException
shutdownInput
in class java.net.Socket
java.io.IOException
public void shutdownOutput() throws java.io.IOException
shutdownOutput
in class java.net.Socket
java.io.IOException
public boolean isInputShutdown()
isInputShutdown
in class java.net.Socket
public boolean isOutputShutdown()
isOutputShutdown
in class java.net.Socket
public void reset() throws java.io.IOException
The socket will attempt to deliver all outstanding bytes to the remote endpoint and then it will renegotiate the connection parameters. The transmissions of bytes resumes after the renegotation finishes and the connection is synchronized again.
java.io.IOException
- if an I/O error occurs when resetting the connection.public void reset(ReliableSocketProfile profile) throws java.io.IOException
The socket will attempt to deliver all outstanding bytes to the remote endpoint and then it will renegotiate the connection parameters specified in the given socket profile. The transmissions of bytes resumes after the renegotation finishes and the connection is synchronized again.
profile
- the socket profile or null if old profile should be used.java.io.IOException
- if an I/O error occurs when resetting the connection.public void addListener(ReliableSocketListener listener)
listener
- the listener to add.public void removeListener(ReliableSocketListener listener)
listener
- the listener to remove.public void addStateListener(ReliableSocketStateListener stateListener)
stateListener
- the listener to add.public void removeStateListener(ReliableSocketStateListener stateListener)
stateListener
- the listener to remove.public static java.util.concurrent.ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()