Here you can find the source of pingWithSocketChannel()
public static boolean pingWithSocketChannel() throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.*; import java.nio.channels.SocketChannel; import static java.lang.System.out; public class Main { public static final String IPv6_ONLY_SERVER_IP = "2001::7"; public static final int IPv6_ONLY_SERVER_PORT = 22; public static boolean pingWithSocketChannel() throws IOException { boolean connected = false; Socket socket = null;/*from w ww .j a v a 2 s. c om*/ try { SocketChannel socketChannel = SocketChannel .open(new InetSocketAddress(IPv6_ONLY_SERVER_IP, IPv6_ONLY_SERVER_PORT)); socket = socketChannel.socket(); out.println("Created!"); connected = true; } catch (IOException e) { out.println("Failed to connect"); e.printStackTrace(out); } finally { if (socket != null) { socket.close(); } } return connected; } }