Source:
public void testTcpSocketKeepalives() throws Exception { final ExecutorService executor = Executors.newSingleThreadExecutor(); final int srcPort = 12345; final int srcPortV6 = 23456; final InetAddress myIPv4 = InetAddress.getByName("127.0.0.1"); final InetAddress notMyIPv4 = InetAddress.getByName("192.0.2.35"); final InetAddress myIPv6 = InetAddress.getByName("::1"); final int validKaInterval = 15; final int invalidKaInterval = 9; LinkProperties lp = new LinkProperties(); lp.setInterfaceName("wlan12"); lp.addLinkAddress(new LinkAddress(myIPv6, 64)); lp.addLinkAddress(new LinkAddress(myIPv4, 25)); lp.addRoute(new RouteInfo(InetAddress.getByName("fe80::1234"))); lp.addRoute(new RouteInfo(InetAddress.getByName("127.0.0.254"))); Network notMyNet = new Network(61234); Network myNet = connectKeepaliveNetwork(lp); final Socket testSocket = new Socket(); final Socket testSocketV6 = new Socket(); TestSocketKeepaliveCallback callback = new TestSocketKeepaliveCallback(); SocketKeepalive ka; ka = mCm.createSocketKeepalive(notMyNet, testSocket, executor, callback); ka.start(validKaInterval); callback.expectError(SocketKeepalive.ERROR_INVALID_NETWORK); ka = mCm.createSocketKeepalive(myNet, testSocket, executor, callback); ka.start(validKaInterval); callback.expectError(SocketKeepalive.ERROR_INVALID_SOCKET); testSocket.bind(new InetSocketAddress(myIPv4, srcPort)); ka = mCm.createSocketKeepalive(myNet, testSocket, executor, callback); ka.start(validKaInterval); callback.expectError(SocketKeepalive.ERROR_INVALID_SOCKET); testSocketV6.bind(new InetSocketAddress(myIPv6, srcPortV6)); ka = mCm.createSocketKeepalive(myNet, testSocketV6, executor, callback); ka.start(validKaInterval); callback.expectError(SocketKeepalive.ERROR_INVALID_SOCKET); testSocket.close(); testSocketV6.close(); executor.shutdown(); }

Target:
public void testTcpSocketKeepalives() throws Exception { final ExecutorService executor = Executors.newSingleThreadExecutor(); final int srcPort = 12345; final int srcPortV6 = 23456; final InetAddress myIPv4 = InetAddress.getByName("127.0.0.1"); final InetAddress myIPv6 = InetAddress.getByName("::1"); final int validKaInterval = 15; final int invalidKaInterval = 9; final LinkProperties lp = new LinkProperties(); lp.setInterfaceName("wlan12"); lp.addLinkAddress(new LinkAddress(myIPv6, 64)); lp.addLinkAddress(new LinkAddress(myIPv4, 25)); lp.addRoute(new RouteInfo(InetAddress.getByName("fe80::1234"))); lp.addRoute(new RouteInfo(InetAddress.getByName("127.0.0.254"))); final Network notMyNet = new Network(61234); final Network myNet = connectKeepaliveNetwork(lp); final Socket testSocketV4 = new Socket(); final Socket testSocketV6 = new Socket(); testSocketV4.bind(new InetSocketAddress(myIPv4, srcPort)); testSocketV6.bind(new InetSocketAddress(myIPv6, srcPortV6)); TestSocketKeepaliveCallback callback = new TestSocketKeepaliveCallback(); SocketKeepalive ka; ka = mCm.createSocketKeepalive(notMyNet, testSocketV4, executor, callback); ka.start(validKaInterval); callback.expectError(SocketKeepalive.ERROR_INVALID_NETWORK); ka = mCm.createSocketKeepalive(myNet, testSocketV4, executor, callback); ka.start(validKaInterval); callback.expectError(SocketKeepalive.ERROR_INVALID_SOCKET); ka = mCm.createSocketKeepalive(myNet, testSocketV4, executor, callback); ka.start(validKaInterval); callback.expectError(SocketKeepalive.ERROR_INVALID_SOCKET); ka = mCm.createSocketKeepalive(myNet, testSocketV6, executor, callback); ka.start(validKaInterval); callback.expectError(SocketKeepalive.ERROR_INVALID_SOCKET); testSocketV4.close(); testSocketV6.close(); executor.shutdown(); }