public class ReliableSocket
extends java.net.Socket
Socket| Modifier and Type | Field and Description |
|---|---|
protected java.net.SocketAddress |
_endpoint |
protected net.rudp.ReliableSocketInputStream |
_in |
protected net.rudp.ReliableSocketOutputStream |
_out |
protected java.net.DatagramSocket |
_sock |
| Modifier | Constructor and Description |
|---|---|
|
ReliableSocket()
Creates an unconnected RUDP socket with default RUDP parameters.
|
|
ReliableSocket(java.net.DatagramSocket sock)
Creates a RUDP socket and attaches it to the underlying datagram socket.
|
protected |
ReliableSocket(java.net.DatagramSocket sock,
ReliableSocketProfile profile)
Creates a RUDP socket and attaches it to the underlying
datagram socket using the given 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.
|
protected |
ReliableSocket(java.net.InetSocketAddress inetAddr,
java.net.InetSocketAddress localAddr)
Creates a RUDP socket and connects it to the specified remote address.
|
|
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() |
protected void |
closeImpl()
Cleans up and closes the socket.
|
protected void |
closeSocket()
Closes the underlying UDP socket.
|
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() |
int |
getSendBufferSize() |
boolean |
getTcpNoDelay() |
protected void |
init(java.net.DatagramSocket sock,
ReliableSocketProfile profile)
Initializes socket and sets it up for receiving incoming traffic.
|
boolean |
isBound() |
boolean |
isClosed() |
boolean |
isConnected() |
boolean |
isInputShutdown() |
boolean |
isOutputShutdown() |
protected void |
log(java.lang.String msg)
Log routine.
|
protected int |
read(byte[] b,
int off,
int len)
Reads up to
len bytes of data from the receiver
buffer into an array of bytes. |
protected net.rudp.impl.Segment |
receiveSegmentImpl()
Reads in a segment from the underlying UDP socket.
|
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.
|
protected void |
sendSegmentImpl(net.rudp.impl.Segment s)
Writes out a segment to the underlying UDP socket.
|
void |
setKeepAlive(boolean on) |
void |
setReceiveBufferSize(int size) |
void |
setSendBufferSize(int size) |
void |
setSoTimeout(int timeout) |
void |
setTcpNoDelay(boolean on) |
void |
shutdownInput() |
void |
shutdownOutput() |
protected void |
write(byte[] b,
int off,
int len)
Writes
len bytes from the specified byte array
starting at offset off as data segments and
queues them for immediate transmission. |
protected java.net.DatagramSocket _sock
protected java.net.SocketAddress _endpoint
protected net.rudp.ReliableSocketInputStream _in
protected net.rudp.ReliableSocketOutputStream _out
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.protected ReliableSocket(java.net.InetSocketAddress inetAddr,
java.net.InetSocketAddress localAddr)
throws java.io.IOException
inetAddr - the remote address.localAddr - the local address.java.io.IOException - if an I/O error occurs when creating the socket.public ReliableSocket(java.net.DatagramSocket sock)
sock - the datagram socket.protected ReliableSocket(java.net.DatagramSocket sock,
ReliableSocketProfile profile)
sock - the datagram socket.profile - the socket profile.protected void init(java.net.DatagramSocket sock,
ReliableSocketProfile profile)
sock - the datagram socket.profile - the socket profile.public void bind(java.net.SocketAddress bindpoint)
throws java.io.IOException
bind in class java.net.Socketjava.io.IOExceptionpublic void connect(java.net.SocketAddress endpoint)
throws java.io.IOException
connect in class java.net.Socketjava.io.IOExceptionpublic void connect(java.net.SocketAddress endpoint,
int timeout)
throws java.io.IOException
connect in class java.net.Socketjava.io.IOExceptionpublic java.nio.channels.SocketChannel getChannel()
getChannel in class java.net.Socketpublic java.net.InetAddress getInetAddress()
getInetAddress in class java.net.Socketpublic int getPort()
getPort in class java.net.Socketpublic java.net.SocketAddress getRemoteSocketAddress()
getRemoteSocketAddress in class java.net.Socketpublic java.net.InetAddress getLocalAddress()
getLocalAddress in class java.net.Socketpublic int getLocalPort()
getLocalPort in class java.net.Socketpublic java.net.SocketAddress getLocalSocketAddress()
getLocalSocketAddress in class java.net.Socketpublic java.io.InputStream getInputStream()
throws java.io.IOException
getInputStream in class java.net.Socketjava.io.IOExceptionpublic java.io.OutputStream getOutputStream()
throws java.io.IOException
getOutputStream in class java.net.Socketjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.net.Socketjava.io.IOExceptionpublic boolean isBound()
isBound in class java.net.Socketpublic boolean isConnected()
isConnected in class java.net.Socketpublic boolean isClosed()
isClosed in class java.net.Socketpublic void setSoTimeout(int timeout)
throws java.net.SocketException
setSoTimeout in class java.net.Socketjava.net.SocketExceptionpublic void setSendBufferSize(int size)
throws java.net.SocketException
setSendBufferSize in class java.net.Socketjava.net.SocketExceptionpublic int getSendBufferSize()
throws java.net.SocketException
getSendBufferSize in class java.net.Socketjava.net.SocketExceptionpublic void setReceiveBufferSize(int size)
throws java.net.SocketException
setReceiveBufferSize in class java.net.Socketjava.net.SocketExceptionpublic int getReceiveBufferSize()
throws java.net.SocketException
getReceiveBufferSize in class java.net.Socketjava.net.SocketExceptionpublic void setTcpNoDelay(boolean on)
throws java.net.SocketException
setTcpNoDelay in class java.net.Socketjava.net.SocketExceptionpublic boolean getTcpNoDelay()
getTcpNoDelay in class java.net.Socketpublic void setKeepAlive(boolean on)
throws java.net.SocketException
setKeepAlive in class java.net.Socketjava.net.SocketExceptionpublic boolean getKeepAlive()
throws java.net.SocketException
getKeepAlive in class java.net.Socketjava.net.SocketExceptionpublic void shutdownInput()
throws java.io.IOException
shutdownInput in class java.net.Socketjava.io.IOExceptionpublic void shutdownOutput()
throws java.io.IOException
shutdownOutput in class java.net.Socketjava.io.IOExceptionpublic boolean isInputShutdown()
isInputShutdown in class java.net.Socketpublic boolean isOutputShutdown()
isOutputShutdown in class java.net.Socketpublic 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.protected void write(byte[] b,
int off,
int len)
throws java.io.IOException
len bytes from the specified byte array
starting at offset off as data segments and
queues them for immediate transmission.b - the data.off - the start offset in the data.len - the number of bytes to write.java.io.IOException - if an I/O error occurs. In particular,
an IOException is thrown if the socket
is closed.protected int read(byte[] b,
int off,
int len)
throws java.io.IOException
len bytes of data from the receiver
buffer into an array of bytes. An attempt is made to read
as many as len bytes, but a smaller number may
be read. The number of bytes actually read is returned as
an integer.
This method blocks until input data is available, end of file is detected, or an exception is thrown.
b - the buffer into which the data is read.off - the start offset in array b
at which the data is written.len - the maximum number of bytes to read.-1 if there is no more data because
the end of the stream has been reached.java.io.IOException - if an I/O error occurs. In particular,
an IOException is thrown if the socket
is closed, or if the buffer is not big enough to hold
a full data segment.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.protected void sendSegmentImpl(net.rudp.impl.Segment s)
throws java.io.IOException
s - the segment.java.io.IOException - if an I/O error occurs in the
underlying UDP socket.protected net.rudp.impl.Segment receiveSegmentImpl()
throws java.io.IOException
java.io.IOException - if an I/O error occurs in the
underlying UDP socket.protected void closeSocket()
protected void closeImpl()
protected void log(java.lang.String msg)
Copyright © 2009 Adrian Granados. All Rights Reserved.