Class SocketUtil


  • public class SocketUtil
    extends Object
    Utility class to generate Socket instances.
    Author:
    Guus der Kinderen, guus.der.kinderen@gmail.com
    • Field Detail

      • CONNECTION_ATTEMPT_DELAY

        public static final SystemProperty<Duration> CONNECTION_ATTEMPT_DELAY
        A fixed delay for how long to wait before starting the next connection attempt, as defined in section 5 of RFC 8305 "Happy Eyeballs Version 2: Better Connectivity Using Concurrency".
        See Also:
        RFC 8305, section 5
      • RESOLUTION_DELAY

        public static final SystemProperty<Duration> RESOLUTION_DELAY
        The time to wait for a response for the 'preferred IP family' after receiving a response for another family, as defined in section 3 of RFC 8305 "Happy Eyeballs Version 2: Better Connectivity Using Concurrency".
        See Also:
        RFC 8305, section 5
      • RESOLUTION_TIMEOUT

        public static final SystemProperty<Duration> RESOLUTION_TIMEOUT
        The maximum amount of time to wait for successful resolution of a host of a target domain.
        See Also:
        RFC 8305, section 5
      • MAX_CONNECTION_CONCURRENCY

        public static final SystemProperty<Integer> MAX_CONNECTION_CONCURRENCY
        The maximum amount of worker threads attempting to set up a socket connection to a target remote XMPP domain. A value of '1' will effectively make 'Happy Eyeballs' impossible (as that requires concurrent connection attempts).
        See Also:
        RFC 8305, section 5
    • Constructor Detail

      • SocketUtil

        public SocketUtil()
    • Method Detail

      • createSocketToXmppDomain

        public static Map.Entry<Socket,​Boolean> createSocketToXmppDomain​(String xmppDomain,
                                                                               int port)
        Creates a socket connection to an XMPP domain. This implementation uses DNS SRV records to find a list of remote hosts for the XMPP domain (as implemented by DNSUtil.resolveXMPPDomain(String, int)). It then iteratively tries to create a socket connection to each of them, until one socket connection succeeds. Either the connected Socket instance is returned, or null if no connection could be established. Note that this method blocks while performing network IO. The timeout as defined by RemoteServerManager.getSocketTimeout() is observed.
        Parameters:
        xmppDomain - The XMPP domain to connect to.
        port - The port to connect to when DNS resolution fails.
        Returns:
        a Socket instance that is connected, or null.
        See Also:
        DNSUtil.resolveXMPPDomain(String, int)