Package com.zerotier.sockets
Class ZeroTierSocket
java.lang.Object
com.zerotier.sockets.ZeroTierSocket
public class ZeroTierSocket
extends java.lang.Object
Implements Socket-like behavior over ZeroTier
-
Constructor Summary
Constructors Constructor Description ZeroTierSocket(int family, int type, int protocol)
Create a new ZeroTierSocket with the given attributesZeroTierSocket(java.lang.String remoteAddr, int remotePort)
-
Method Summary
Modifier and Type Method Description ZeroTierSocket
accept()
Accept incoming connections on this ZeroTierSocketvoid
bind(java.lang.String localAddr, int localPort)
Bind to a local addressvoid
bind(java.net.InetAddress localAddr, int localPort)
Bind to a local addressvoid
close()
Close the ZeroTierSocket.void
connect(java.lang.String remoteAddr, int remotePort)
Connect to a remote hostvoid
connect(java.net.InetAddress remoteAddr, int remotePort)
Connect to a remote hostvoid
connect(java.net.SocketAddress remoteAddr)
Connect to a remote hostjava.net.InetAddress
getInetAddress()
Get the remote address to which this ZeroTierSocket is connected.ZeroTierInputStream
getInputStream()
Return a reference to the ZeroTierInputStream used by this ZeroTierSocketboolean
getKeepAlive()
Return whether keepalive is enabled.java.net.InetAddress
getLocalAddress()
Get the local address to which this ZeroTierSocket is boundint
getLocalPort()
Get the local port to which this ZeroTierSocket is boundjava.net.SocketAddress
getLocalSocketAddress()
Get the local endpoint address to which this socket is bound toint
getNativeFileDescriptor()
ZeroTierOutputStream
getOutputStream()
Return a reference to the ZeroTierOutputStream used by this ZeroTierSocketint
getReceiveBufferSize()
Return the size of the receive buffer for the ZeroTierSocket's ZeroTierInputStream (SO_RCVBUF)java.net.InetAddress
getRemoteAddress()
Get the remote address to which this ZeroTierSocket is connectedint
getRemotePort()
Get the remote port to which this ZeroTierSocket is connectedboolean
getReuseAddress()
Return whether address reuse is enabled on this ZeroTierSocket (SO_REUSEADDR)int
getSendBufferSize()
Return the size of the send buffer for the ZeroTierSocket's ZeroTierOutputStream (SO_SNDBUF)int
getSoLingerTime()
Return the amount of time that a ZeroTierSocket will linger after closure (SO_LINGER)int
getSoTimeout()
Get the ZeroTierSocket's timeout value (SO_RCVTIMEO)boolean
inputStreamHasBeenShutdown()
Return whether the input-aspect of the ZeroTierSocket has been disabled.boolean
isBound()
Return whether this ZeroTierSocket is bound to a local addressboolean
isClosed()
Return whether this ZeroTierSocket has been closedboolean
isConnected()
Return whether this ZeroTierSocket is connected to a remote addressvoid
listen(int backlog)
Put the ZeroTierSocket into a listening stateboolean
outputStreamHasBeenShutdown()
Return whether the output-aspect of the ZeroTierSocket has been disabled.void
setKeepAliveEnabled(boolean enabled)
Enable or disable the keepalive setting (SO_KEEPALIVE)void
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
setSendBufferSize(int bufferSize)
Set the size of the send buffer for the ZeroTierSocket's ZeroTierOutputStream (SO_SNDBUF)void
setSoLinger(boolean enabled, int lingerTime)
Set the amount of time that a ZeroTierSocket will linger after closure (SO_LINGER)void
setSoTimeout(int timeout)
Set the timeout value for SO_RCVTIMEOvoid
setTcpNoDelayEnabled(boolean enabled)
Enable or disable TCP_NODELAYvoid
shutdownInput()
Disable the input-aspect of the ZeroTierSocket.void
shutdownOutput()
Disable the output-aspect of the ZeroTierSocket.boolean
tcpNoDelayEnabled()
Return whether TCP no-delay is enabled (TCP_NODELAY)Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
ZeroTierSocket
public ZeroTierSocket(java.lang.String remoteAddr, int remotePort) throws java.io.IOException- Throws:
java.io.IOException
-
ZeroTierSocket
public ZeroTierSocket(int family, int type, int protocol) throws java.io.IOExceptionCreate a new ZeroTierSocket with the given attributes- Parameters:
family
- The socket familytype
- The socket typeprotocol
- Supported protocol- Throws:
java.io.IOException
- when an I/O error occurs
-
-
Method Details
-
getNativeFileDescriptor
public int getNativeFileDescriptor() -
connect
public void connect(java.net.InetAddress remoteAddr, int remotePort) throws java.io.IOExceptionConnect to a remote host- Parameters:
remoteAddr
- Remote address to which this socket should connectremotePort
- Remote port to which this socket should connect- Throws:
java.io.IOException
- when an I/O error occurs
-
connect
public void connect(java.lang.String remoteAddr, int remotePort) throws java.io.IOExceptionConnect to a remote host- Parameters:
remoteAddr
- Remote address to which this socket should connectremotePort
- Remote port to which this socket should connect- Throws:
java.io.IOException
- when an I/O error occurs
-
connect
public void connect(java.net.SocketAddress remoteAddr) throws java.io.IOExceptionConnect to a remote host- Parameters:
remoteAddr
- Remote address to which this socket should connect- Throws:
java.io.IOException
- when an I/O error occurs
-
bind
public void bind(java.net.InetAddress localAddr, int localPort) 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.lang.String localAddr, int localPort) 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
-
listen
public void listen(int backlog) throws java.io.IOExceptionPut the ZeroTierSocket into a listening state- Parameters:
backlog
- Size of connection backlog- Throws:
java.io.IOException
- when an I/O error occurs
-
accept
Accept incoming connections on this ZeroTierSocket- Returns:
- New ZeroTierSocket representing the accepted connection
- 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
-
getKeepAlive
public boolean getKeepAlive() throws java.net.SocketExceptionReturn whether keepalive is enabled.- Returns:
- true or false
- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-
getLocalPort
public int getLocalPort()Get the local port to which this ZeroTierSocket is bound- Returns:
- Local port
-
getLocalAddress
public java.net.InetAddress getLocalAddress()Get the local address to which this ZeroTierSocket is bound- Returns:
- Local address
-
getRemotePort
public int getRemotePort()Get the remote port to which this ZeroTierSocket is connected- Returns:
- Remote port
-
getRemoteAddress
public java.net.InetAddress getRemoteAddress()Get the remote address to which this ZeroTierSocket is connected- Returns:
- Remote address
-
getInetAddress
public java.net.InetAddress getInetAddress()Get the remote address to which this ZeroTierSocket is connected. Same as getRemoteAddress()- Returns:
- Remote address
-
getLocalSocketAddress
public java.net.SocketAddress getLocalSocketAddress()Get the local endpoint address to which this socket is bound to- Returns:
- Local endpoint address
-
getReceiveBufferSize
public int getReceiveBufferSize() throws java.net.SocketExceptionReturn 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 layer
-
getSendBufferSize
public int getSendBufferSize() throws java.net.SocketExceptionReturn the size of the send buffer for the ZeroTierSocket's ZeroTierOutputStream (SO_SNDBUF)- Returns:
- Size of the send buffer
- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-
getReuseAddress
public boolean getReuseAddress() throws java.net.SocketExceptionReturn 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 layer
-
getSoLingerTime
public int getSoLingerTime() throws java.net.SocketExceptionReturn the amount of time that a ZeroTierSocket will linger after closure (SO_LINGER)- Returns:
- Nothing.
- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-
getSoTimeout
public int getSoTimeout() throws java.net.SocketExceptionGet the ZeroTierSocket's timeout value (SO_RCVTIMEO)- Returns:
- Nothing.
- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-
tcpNoDelayEnabled
public boolean tcpNoDelayEnabled() throws java.net.SocketExceptionReturn whether TCP no-delay is enabled (TCP_NODELAY)- Returns:
- true or false
- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-
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
-
isConnected
public boolean isConnected()Return whether this ZeroTierSocket is connected to a remote address- Returns:
- true or false
-
shutdownInput
public void shutdownInput() throws java.net.SocketExceptionDisable the input-aspect of the ZeroTierSocket.- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-
shutdownOutput
public void shutdownOutput() throws java.net.SocketExceptionDisable the output-aspect of the ZeroTierSocket.- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-
getInputStream
Return a reference to the ZeroTierInputStream used by this ZeroTierSocket- Returns:
- A reference to the ZeroTierInputStream
- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-
getOutputStream
Return a reference to the ZeroTierOutputStream used by this ZeroTierSocket- Returns:
- A reference to the ZeroTierOutputStream
- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-
inputStreamHasBeenShutdown
public boolean inputStreamHasBeenShutdown()Return whether the input-aspect of the ZeroTierSocket has been disabled.- Returns:
- true or false
-
outputStreamHasBeenShutdown
public boolean outputStreamHasBeenShutdown()Return whether the output-aspect of the ZeroTierSocket has been disabled.- Returns:
- true or false
-
setKeepAliveEnabled
public void setKeepAliveEnabled(boolean enabled) throws java.net.SocketExceptionEnable or disable the keepalive setting (SO_KEEPALIVE)- Parameters:
enabled
- Whether SO_KEEPALIVE is enabled.- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-
setReceiveBufferSize
public void setReceiveBufferSize(int bufferSize) throws java.net.SocketExceptionSet 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 layer
-
setReuseAddress
public void setReuseAddress(boolean enabled) throws java.net.SocketExceptionEnable 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 layer
-
setSendBufferSize
public void setSendBufferSize(int bufferSize) throws java.net.SocketExceptionSet the size of the send buffer for the ZeroTierSocket's ZeroTierOutputStream (SO_SNDBUF)- Parameters:
bufferSize
- Size of send buffer- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-
setSoLinger
public void setSoLinger(boolean enabled, int lingerTime) throws java.net.SocketExceptionSet the amount of time that a ZeroTierSocket will linger after closure (SO_LINGER)- Parameters:
enabled
- Whether SO_LINGER is enabledlingerTime
- SO_LINGER time- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-
setSoTimeout
public void setSoTimeout(int timeout) throws java.net.SocketExceptionSet the timeout value for SO_RCVTIMEO- Parameters:
timeout
- Socket receive timeout value.- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-
setTcpNoDelayEnabled
public void setTcpNoDelayEnabled(boolean enabled) throws java.net.SocketExceptionEnable or disable TCP_NODELAY- Parameters:
enabled
- Whether TCP_NODELAY is enabled- Throws:
java.net.SocketException
- when an error occurs in the native socket layer
-