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 attributes
    ZeroTierSocket​(java.lang.String remoteAddr, int remotePort)  
  • Method Summary

    Modifier and Type Method Description
    ZeroTierSocket accept()
    Accept incoming connections on this ZeroTierSocket
    void bind​(java.lang.String localAddr, int localPort)
    Bind to a local address
    void bind​(java.net.InetAddress localAddr, int localPort)
    Bind to a local address
    void close()
    Close the ZeroTierSocket.
    void connect​(java.lang.String remoteAddr, int remotePort)
    Connect to a remote host
    void connect​(java.net.InetAddress remoteAddr, int remotePort)
    Connect to a remote host
    void connect​(java.net.SocketAddress remoteAddr)
    Connect to a remote host
    java.net.InetAddress getInetAddress()
    Get the remote address to which this ZeroTierSocket is connected.
    ZeroTierInputStream getInputStream()
    Return a reference to the ZeroTierInputStream used by this ZeroTierSocket
    boolean getKeepAlive()
    Return whether keepalive is enabled.
    java.net.InetAddress getLocalAddress()
    Get the local address to which this ZeroTierSocket is bound
    int getLocalPort()
    Get the local port to which this ZeroTierSocket is bound
    java.net.SocketAddress getLocalSocketAddress()
    Get the local endpoint address to which this socket is bound to
    int getNativeFileDescriptor()  
    ZeroTierOutputStream getOutputStream()
    Return a reference to the ZeroTierOutputStream used by this ZeroTierSocket
    int 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 connected
    int getRemotePort()
    Get the remote port to which this ZeroTierSocket is connected
    boolean 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 address
    boolean isClosed()
    Return whether this ZeroTierSocket has been closed
    boolean isConnected()
    Return whether this ZeroTierSocket is connected to a remote address
    void listen​(int backlog)
    Put the ZeroTierSocket into a listening state
    boolean 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_RCVTIMEO
    void setTcpNoDelayEnabled​(boolean enabled)
    Enable or disable TCP_NODELAY
    void 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.IOException
      Create a new ZeroTierSocket with the given attributes
      Parameters:
      family - The socket family
      type - The socket type
      protocol - 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.IOException
      Connect to a remote host
      Parameters:
      remoteAddr - Remote address to which this socket should connect
      remotePort - 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.IOException
      Connect to a remote host
      Parameters:
      remoteAddr - Remote address to which this socket should connect
      remotePort - 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.IOException
      Connect 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.IOException
      Bind to a local address
      Parameters:
      localAddr - Local address to which this socket should bind
      localPort - 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.IOException
      Bind to a local address
      Parameters:
      localAddr - Local address to which this socket should bind
      localPort - 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.IOException
      Put the ZeroTierSocket into a listening state
      Parameters:
      backlog - Size of connection backlog
      Throws:
      java.io.IOException - when an I/O error occurs
    • accept

      public ZeroTierSocket accept() throws java.io.IOException
      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.IOException
      Close the ZeroTierSocket.
      Throws:
      java.io.IOException - when an I/O error occurs
    • getKeepAlive

      public boolean getKeepAlive() throws java.net.SocketException
      Return 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.SocketException
      Return 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.SocketException
      Return 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.SocketException
      Return 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.SocketException
      Return 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.SocketException
      Get 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.SocketException
      Return 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.SocketException
      Disable 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.SocketException
      Disable the output-aspect of the ZeroTierSocket.
      Throws:
      java.net.SocketException - when an error occurs in the native socket layer
    • getInputStream

      public ZeroTierInputStream getInputStream() throws java.net.SocketException
      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

      public ZeroTierOutputStream getOutputStream() throws java.net.SocketException
      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.SocketException
      Enable 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.SocketException
      Set 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.SocketException
      Enable 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.SocketException
      Set 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.SocketException
      Set the amount of time that a ZeroTierSocket will linger after closure (SO_LINGER)
      Parameters:
      enabled - Whether SO_LINGER is enabled
      lingerTime - 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.SocketException
      Set 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.SocketException
      Enable or disable TCP_NODELAY
      Parameters:
      enabled - Whether TCP_NODELAY is enabled
      Throws:
      java.net.SocketException - when an error occurs in the native socket layer