Package com.zerotier.sockets
Class ZeroTierServerSocket
java.lang.Object
com.zerotier.sockets.ZeroTierServerSocket
public class ZeroTierServerSocket
extends java.lang.Object
Implements SocketServer-like behavior over ZeroTier
-
Constructor Summary
Constructors Constructor Description ZeroTierServerSocket()Create an unbound ZeroTierServerSocketZeroTierServerSocket(int localPort)Create a ZeroTierServerSocket bound to the given portZeroTierServerSocket(int localPort, int backlog)Create a ZeroTierServerSocket bound to the given port with a backlogZeroTierServerSocket(int localPort, int backlog, java.net.InetAddress localAddr)Create a ZeroTierServerSocket bound to the given port and local address -
Method Summary
Modifier and Type Method Description ZeroTierSocketaccept()Accept incoming connections on this ZeroTierSocketvoidbind(java.net.SocketAddress localAddr)Bind to a local addressvoidbind(java.net.SocketAddress localAddr, int backlog)Bind to a local addressvoidclose()Close the ZeroTierSocket.java.net.InetAddressgetInetAddress()Get the remote address to which this ZeroTierSocket is boundintgetLocalPort()Get the local port to which this ZeroTierSocket is boundjava.net.SocketAddressgetLocalSocketAddress()Get the local address to which this ZeroTierSocket is boundintgetReceiveBufferSize()Return the size of the receive buffer for the ZeroTierSocket's ZeroTierInputStream (SO_RCVBUF)booleangetReuseAddress()Return whether address reuse is enabled on this ZeroTierSocket (SO_REUSEADDR)intgetSoTimeout()Get the ZeroTierSocket's timeout value (SO_RCVTIMEO)booleanisBound()Return whether this ZeroTierSocket is bound to a local addressbooleanisClosed()Return whether this ZeroTierSocket has been closedvoidsetReceiveBufferSize(int bufferSize)Set the size of the receive buffer for the ZeroTierSocket's ZeroTierInputStream.voidsetReuseAddress(boolean enabled)Enable or disable the re-use of addresses (SO_REUSEADDR)voidsetSoTimeout(int timeout)Set the timeout value for SO_RCVTIMEOMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
ZeroTierServerSocket
public ZeroTierServerSocket() throws java.io.IOExceptionCreate an unbound ZeroTierServerSocket- Throws:
java.io.IOException
-
ZeroTierServerSocket
public ZeroTierServerSocket(int localPort) throws java.io.IOExceptionCreate a ZeroTierServerSocket bound to the given port- Throws:
java.io.IOException
-
ZeroTierServerSocket
public ZeroTierServerSocket(int localPort, int backlog) throws java.io.IOExceptionCreate a ZeroTierServerSocket bound to the given port with a backlog- Throws:
java.io.IOException
-
ZeroTierServerSocket
public ZeroTierServerSocket(int localPort, int backlog, java.net.InetAddress localAddr) throws java.io.IOExceptionCreate a ZeroTierServerSocket bound to the given port and local address- Throws:
java.io.IOException
-
-
Method Details
-
accept
Accept incoming connections on this ZeroTierSocket- Returns:
- New ZeroTierSocket representing the accepted connection
- Throws:
java.io.IOException- when an I/O error occurs
-
bind
public void bind(java.net.SocketAddress localAddr) throws java.io.IOExceptionBind to a local address- Parameters:
localAddr- Local address to which this socket should bindlocalPort- Local port to which this socket should bind- Throws:
java.io.IOException- when an I/O error occurs
-
bind
public void bind(java.net.SocketAddress localAddr, int backlog) throws java.io.IOExceptionBind to a local address- Parameters:
localAddr- Local address to which this socket should bindlocalPort- Local port to which this socket should bind- Throws:
java.io.IOException- when an I/O error occurs
-
close
public void close() throws java.io.IOExceptionClose the ZeroTierSocket.- Throws:
java.io.IOException- when an I/O error occurs
-
getInetAddress
public java.net.InetAddress getInetAddress()Get the remote address to which this ZeroTierSocket is bound- Returns:
- Remote address
-
getLocalPort
public int getLocalPort()Get the local port to which this ZeroTierSocket is bound- Returns:
- Local port
-
getLocalSocketAddress
public java.net.SocketAddress getLocalSocketAddress()Get the local address to which this ZeroTierSocket is bound- Returns:
- Local address
-
getReceiveBufferSize
public int getReceiveBufferSize() throws java.io.IOExceptionReturn the size of the receive buffer for the ZeroTierSocket's ZeroTierInputStream (SO_RCVBUF)- Returns:
- Size of the receive buffer
- Throws:
java.net.SocketException- when an error occurs in the native socket layerjava.io.IOException
-
getReuseAddress
public boolean getReuseAddress() throws java.io.IOExceptionReturn whether address reuse is enabled on this ZeroTierSocket (SO_REUSEADDR)- Returns:
- true or false
- Throws:
java.net.SocketException- when an error occurs in the native socket layerjava.io.IOException
-
getSoTimeout
public int getSoTimeout() throws java.io.IOExceptionGet the ZeroTierSocket's timeout value (SO_RCVTIMEO)- Returns:
- Nothing.
- Throws:
java.net.SocketException- when an error occurs in the native socket layerjava.io.IOException
-
isBound
public boolean isBound()Return whether this ZeroTierSocket is bound to a local address- Returns:
- true or false
-
isClosed
public boolean isClosed()Return whether this ZeroTierSocket has been closed- Returns:
- true or false
-
setReceiveBufferSize
public void setReceiveBufferSize(int bufferSize) throws java.io.IOExceptionSet the size of the receive buffer for the ZeroTierSocket's ZeroTierInputStream.- Parameters:
bufferSize- Size of receive buffer- Throws:
java.net.SocketException- when an error occurs in the native socket layerjava.io.IOException
-
setReuseAddress
public void setReuseAddress(boolean enabled) throws java.io.IOExceptionEnable or disable the re-use of addresses (SO_REUSEADDR)- Parameters:
enabled- Whether SO_REUSEADDR is enabled- Throws:
java.net.SocketException- when an error occurs in the native socket layerjava.io.IOException
-
setSoTimeout
public void setSoTimeout(int timeout) throws java.io.IOExceptionSet the timeout value for SO_RCVTIMEO- Parameters:
timeout- Socket receive timeout value.- Throws:
java.net.SocketException- when an error occurs in the native socket layerjava.io.IOException
-