Package net.rudp
Class ReliableServerSocket
- java.lang.Object
-
- java.net.ServerSocket
-
- net.rudp.ReliableServerSocket
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class ReliableServerSocket extends java.net.ServerSocket
This class implements server sockets that use the Simple Reliable UDP (RUDP) protocol.- Author:
- Adrian Granados
- See Also:
ServerSocket
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ReliableServerSocket.ReliableClientSocket
-
Constructor Summary
Constructors Constructor Description ReliableServerSocket()
Creates an unbound RUDP server socket.ReliableServerSocket(int port)
Creates a RUDP server socket, bound to the specified port.ReliableServerSocket(int port, int backlog)
Creates a RUDP server socket and binds it to the specified local port, with the specified backlog.ReliableServerSocket(int port, int backlog, java.net.InetAddress bindAddr)
Creates a RUDP server socket and binds it to the specified local port and IP address, with the specified backlog.ReliableServerSocket(java.net.DatagramSocket sock, int backlog)
Creates a RUDP server socket attached to the specified UDP socket, with the specified backlog.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.net.Socket
accept()
void
bind(java.net.SocketAddress endpoint)
void
bind(java.net.SocketAddress endpoint, int backlog)
void
close()
java.net.InetAddress
getInetAddress()
int
getLocalPort()
java.net.SocketAddress
getLocalSocketAddress()
int
getSoTimeout()
boolean
isBound()
boolean
isClosed()
void
setSoTimeout(int timeout)
-
-
-
Constructor Detail
-
ReliableServerSocket
public ReliableServerSocket() throws java.io.IOException
Creates an unbound RUDP server socket.- Throws:
java.io.IOException
- if an I/O error occurs when opening the underlying UDP socket.- See Also:
ServerSocket()
-
ReliableServerSocket
public ReliableServerSocket(int port) throws java.io.IOException
Creates a RUDP server socket, bound to the specified port. A port of0
creates a socket on any free port. The maximum queue length for incoming connection indications (a request to connect) is set to50
. If a connection indication arrives when the queue is full, the connection is refused.- Parameters:
port
- the port number, or0
to use any free port.- Throws:
java.io.IOException
- if an I/O error occurs when opening the underlying UDP socket.- See Also:
ServerSocket(int)
-
ReliableServerSocket
public ReliableServerSocket(int port, int backlog) throws java.io.IOException
Creates a RUDP server socket and binds it to the specified local port, with the specified backlog. A port of0
creates a socket on any free port.- Parameters:
port
- the port number, or0
to use any free port.backlog
- the listen backlog.- Throws:
java.io.IOException
- if an I/O error occurs when opening the underlying UDP socket.- See Also:
ServerSocket(int, int)
-
ReliableServerSocket
public ReliableServerSocket(int port, int backlog, java.net.InetAddress bindAddr) throws java.io.IOException
Creates a RUDP server socket and binds it to the specified local port and IP address, with the specified backlog. The bindAddr argument can be used on a multi-homed host for a ReliableServerSocket that will only accept connect requests to one of its addresses. If bindAddr is null, it will default accepting connections on any/all local addresses. A port of0
creates a socket on any free port.- Parameters:
port
- the port number, or0
to use any free port.backlog
- the listen backlog.bindAddr
- the local InetAddress the server will bind to.- Throws:
java.io.IOException
- if an I/O error occurs when opening the underlying UDP socket.- See Also:
ServerSocket(int, int, InetAddress)
-
ReliableServerSocket
public ReliableServerSocket(java.net.DatagramSocket sock, int backlog) throws java.io.IOException
Creates a RUDP server socket attached to the specified UDP socket, with the specified backlog.- Parameters:
sock
- the underlying UDP socket.backlog
- the listen backlog.- Throws:
java.io.IOException
- if an I/O error occurs.
-
-
Method Detail
-
accept
public java.net.Socket accept() throws java.io.IOException
- Overrides:
accept
in classjava.net.ServerSocket
- Throws:
java.io.IOException
-
bind
public void bind(java.net.SocketAddress endpoint) throws java.io.IOException
- Overrides:
bind
in classjava.net.ServerSocket
- Throws:
java.io.IOException
-
bind
public void bind(java.net.SocketAddress endpoint, int backlog) throws java.io.IOException
- Overrides:
bind
in classjava.net.ServerSocket
- Throws:
java.io.IOException
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.net.ServerSocket
-
getInetAddress
public java.net.InetAddress getInetAddress()
- Overrides:
getInetAddress
in classjava.net.ServerSocket
-
getLocalPort
public int getLocalPort()
- Overrides:
getLocalPort
in classjava.net.ServerSocket
-
getLocalSocketAddress
public java.net.SocketAddress getLocalSocketAddress()
- Overrides:
getLocalSocketAddress
in classjava.net.ServerSocket
-
isBound
public boolean isBound()
- Overrides:
isBound
in classjava.net.ServerSocket
-
isClosed
public boolean isClosed()
- Overrides:
isClosed
in classjava.net.ServerSocket
-
setSoTimeout
public void setSoTimeout(int timeout)
- Overrides:
setSoTimeout
in classjava.net.ServerSocket
-
getSoTimeout
public int getSoTimeout()
- Overrides:
getSoTimeout
in classjava.net.ServerSocket
-
-