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 ZeroTierServerSocket
    ZeroTierServerSocket​(int localPort)
    Create a ZeroTierServerSocket bound to the given port
    ZeroTierServerSocket​(int localPort, int backlog)
    Create a ZeroTierServerSocket bound to the given port with a backlog
    ZeroTierServerSocket​(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 ZeroTierSocket
    void bind​(java.net.SocketAddress localAddr)
    Bind to a local address
    void bind​(java.net.SocketAddress localAddr, int backlog)
    Bind to a local address
    void close()
    Close the ZeroTierSocket.
    java.net.InetAddress getInetAddress()
    Get the remote 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 address to which this ZeroTierSocket is bound
    int 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 address
    boolean isClosed()
    Return whether this ZeroTierSocket has been closed
    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 setSoTimeout​(int timeout)
    Set the timeout value for SO_RCVTIMEO

    Methods 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.IOException
      Create an unbound ZeroTierServerSocket
      Throws:
      java.io.IOException
    • ZeroTierServerSocket

      public ZeroTierServerSocket​(int localPort) throws java.io.IOException
      Create a ZeroTierServerSocket bound to the given port
      Throws:
      java.io.IOException
    • ZeroTierServerSocket

      public ZeroTierServerSocket​(int localPort, int backlog) throws java.io.IOException
      Create 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.IOException
      Create a ZeroTierServerSocket bound to the given port and local address
      Throws:
      java.io.IOException
  • Method Details

    • 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
    • bind

      public void bind​(java.net.SocketAddress localAddr) 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.net.SocketAddress localAddr, int backlog) 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
    • close

      public void close() throws java.io.IOException
      Close 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.IOException
      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
      java.io.IOException
    • getReuseAddress

      public boolean getReuseAddress() throws java.io.IOException
      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
      java.io.IOException
    • getSoTimeout

      public int getSoTimeout() throws java.io.IOException
      Get the ZeroTierSocket's timeout value (SO_RCVTIMEO)
      Returns:
      Nothing.
      Throws:
      java.net.SocketException - when an error occurs in the native socket layer
      java.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.IOException
      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
      java.io.IOException
    • setReuseAddress

      public void setReuseAddress​(boolean enabled) throws java.io.IOException
      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
      java.io.IOException
    • setSoTimeout

      public void setSoTimeout​(int timeout) throws java.io.IOException
      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
      java.io.IOException