Class ZeroTierDatagramSocket

java.lang.Object
com.zerotier.sockets.ZeroTierDatagramSocket

public class ZeroTierDatagramSocket
extends java.lang.Object
Implements Socket-like behavior over ZeroTier
  • Constructor Summary

    Constructors
    Constructor Description
    ZeroTierDatagramSocket()
    Create a ZeroTierDatagramSocket and bind it to any available port
    ZeroTierDatagramSocket​(int localPort)
    Create a ZeroTierDatagramSocket bound to the given port
    ZeroTierDatagramSocket​(int localPort, java.net.InetAddress localAddr)
    Create a ZeroTierDatagramSocket bound to the given port and local address
    ZeroTierDatagramSocket​(java.lang.String localAddr, int localPort)
    Create a ZeroTierDatagramSocket bound to the given port and local address
    ZeroTierDatagramSocket​(java.net.SocketAddress localAddr)
    Create a ZeroTierDatagramSocket bound to the given endpoint
  • Method Summary

    Modifier and Type Method Description
    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.
    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 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 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
    boolean isConnected()
    Return whether this ZeroTierSocket is connected to a remote address
    void receive​(java.net.DatagramPacket packet)
    Receive a DatagramPacket from a remote host
    void send​(java.net.DatagramPacket packet)
    Send a DatagramPacket to a remote host
    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 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

    • ZeroTierDatagramSocket

      public ZeroTierDatagramSocket() throws java.io.IOException
      Create a ZeroTierDatagramSocket and bind it to any available port
      Throws:
      java.io.IOException
    • ZeroTierDatagramSocket

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

      public ZeroTierDatagramSocket​(int localPort, java.net.InetAddress localAddr) throws java.io.IOException
      Create a ZeroTierDatagramSocket bound to the given port and local address
      Throws:
      java.io.IOException
    • ZeroTierDatagramSocket

      public ZeroTierDatagramSocket​(java.lang.String localAddr, int localPort) throws java.io.IOException
      Create a ZeroTierDatagramSocket bound to the given port and local address
      Throws:
      java.io.IOException
    • ZeroTierDatagramSocket

      public ZeroTierDatagramSocket​(java.net.SocketAddress localAddr) throws java.io.IOException
      Create a ZeroTierDatagramSocket bound to the given endpoint
      Throws:
      java.io.IOException
  • Method Details

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

      public void send​(java.net.DatagramPacket packet) throws java.io.IOException
      Send a DatagramPacket to a remote host
      Parameters:
      packet - The packet to send
      Throws:
      java.io.IOException - when an I/O error occurs
    • receive

      public void receive​(java.net.DatagramPacket packet) throws java.io.IOException
      Receive a DatagramPacket from a remote host
      Parameters:
      packet - The packet received
      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
    • 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
    • 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
    • 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
    • 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
    • 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