Package com.zerotier.sockets
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 portZeroTierDatagramSocket(int localPort)
Create a ZeroTierDatagramSocket bound to the given portZeroTierDatagramSocket(int localPort, java.net.InetAddress localAddr)
Create a ZeroTierDatagramSocket bound to the given port and local addressZeroTierDatagramSocket(java.lang.String localAddr, int localPort)
Create a ZeroTierDatagramSocket bound to the given port and local addressZeroTierDatagramSocket(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 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.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
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
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 closedboolean
isConnected()
Return whether this ZeroTierSocket is connected to a remote addressvoid
receive(java.net.DatagramPacket packet)
Receive a DatagramPacket from a remote hostvoid
send(java.net.DatagramPacket packet)
Send a DatagramPacket to a remote hostvoid
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_RCVTIMEOMethods 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.IOExceptionCreate a ZeroTierDatagramSocket and bind it to any available port- Throws:
java.io.IOException
-
ZeroTierDatagramSocket
public ZeroTierDatagramSocket(int localPort) throws java.io.IOExceptionCreate a ZeroTierDatagramSocket bound to the given port- Throws:
java.io.IOException
-
ZeroTierDatagramSocket
public ZeroTierDatagramSocket(int localPort, java.net.InetAddress localAddr) throws java.io.IOExceptionCreate 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.IOExceptionCreate a ZeroTierDatagramSocket bound to the given port and local address- Throws:
java.io.IOException
-
ZeroTierDatagramSocket
public ZeroTierDatagramSocket(java.net.SocketAddress localAddr) throws java.io.IOExceptionCreate 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.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
-
send
public void send(java.net.DatagramPacket packet) throws java.io.IOExceptionSend 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.IOExceptionReceive 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.IOExceptionClose 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.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
-
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
-
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.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
-
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
-