Package NeoVisionaries.WebSockets
Class SocketInitiator
- java.lang.Object
-
- NeoVisionaries.WebSockets.SocketInitiator
-
public class SocketInitiator extends java.lang.Object
Lets multiple sockets race the given IP addresses until one has been established.
Read included Apache License 2.0:HERE
AllNeoVisionaries.WebSockets.*
Code Obtained From:GitHub 'NV' (Takahiko Kawasaki)
Public Archive.
This follows RFC 6555 (Happy Eyeballs).
Hi-Lited Source-Code:- View Here: NeoVisionaries/WebSockets/SocketInitiator.java
- Open New Browser-Tab: NeoVisionaries/WebSockets/SocketInitiator.java
File Size: 10,873 Bytes Line Count: 374 '\n' Characters Found
-
-
Constructor Summary
Constructors Constructor Description SocketInitiator(javax.net.SocketFactory socketFactory, NeoVisionaries.WebSockets.Address address, int connectTimeout, String[] serverNames, DualStackMode mode, int fallbackDelay)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Socket
establish(InetAddress[] addresses)
-
-
-
Constructor Detail
-
SocketInitiator
public SocketInitiator(javax.net.SocketFactory socketFactory, NeoVisionaries.WebSockets.Address address, int connectTimeout, java.lang.String[] serverNames, DualStackMode mode, int fallbackDelay)
-
-
Method Detail
-
establish
public java.net.Socket establish(java.net.InetAddress[] addresses) throws java.lang.Exception
- Throws:
java.lang.Exception
- Code:
- Exact Method Body:
// Create socket future. SocketFuture future = new SocketFuture(); // Create socket racer for each IP address. List<SocketRacer> racers = new ArrayList<SocketRacer>(addresses.length); int delay = 0; Signal startSignal = null; for (InetAddress address: addresses) { // Check if the mode requires us to skip this address. if (mMode == DualStackMode.IPV4_ONLY && !(address instanceof Inet4Address) || mMode == DualStackMode.IPV6_ONLY && !(address instanceof Inet6Address)) { continue; } // Increase the *happy eyeballs* delay (see RFC 6555, sec 5.5). delay += mFallbackDelay; // Create the *done* signal which acts as a *start* signal for the subsequent racer. Signal doneSignal = new Signal(delay); // Create racer to establish the socket. SocketAddress socketAddress = new InetSocketAddress(address, mAddress.getPort()); SocketRacer racer = new SocketRacer( future, mSocketFactory, socketAddress, mServerNames, mConnectTimeout, startSignal, doneSignal); racers.add(racer); // Replace *start* signal with this racer's *done* signal. startSignal = doneSignal; } // Wait until one of the sockets has been established, or all failed with an exception. return future.await(racers);
-
-