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 ZeroTierSocket
accept()
Accept incoming connections on this ZeroTierSocketvoid
bind(java.net.SocketAddress localAddr)
Bind to a local addressvoid
bind(java.net.SocketAddress localAddr, int backlog)
Bind to a local addressvoid
close()
Close the ZeroTierSocket.java.net.InetAddress
getInetAddress()
Get the remote address to which this ZeroTierSocket is boundint
getLocalPort()
Get the local port to which this ZeroTierSocket is boundjava.net.SocketAddress
getLocalSocketAddress()
Get the local address to which this ZeroTierSocket is boundint
getReceiveBufferSize()
Return the size of the receive buffer for the ZeroTierSocket's ZeroTierInputStream (SO_RCVBUF)boolean
getReuseAddress()
Return whether address reuse is enabled on this ZeroTierSocket (SO_REUSEADDR)int
getSoTimeout()
Get the ZeroTierSocket's timeout value (SO_RCVTIMEO)boolean
isBound()
Return whether this ZeroTierSocket is bound to a local addressboolean
isClosed()
Return whether this ZeroTierSocket has been closedvoid
setReceiveBufferSize(int bufferSize)
Set the size of the receive buffer for the ZeroTierSocket's ZeroTierInputStream.void
setReuseAddress(boolean enabled)
Enable or disable the re-use of addresses (SO_REUSEADDR)void
setSoTimeout(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
-