Java SocketChannel pingWithSocketChannel()

Here you can find the source of pingWithSocketChannel()

Description

ping With Socket Channel

License

Open Source License

Declaration

public static boolean pingWithSocketChannel() throws IOException 

Method Source Code


//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;
    }
}

Related

  1. finishConnect(SocketChannel socketChannel)
  2. getConnectedSocketChannel(InetAddress host, int port, int timeout)
  3. getSocketAddress(SocketChannel socketChannel)
  4. getSocketDisplayString(SocketChannel channel)
  5. openSocketChannel(SocketAddress sa)
  6. remoteAddress(SocketChannel channel)
  7. sendFile(FileChannel fileChannel, SocketChannel socketChannel)
  8. tune_tcp_socket(SocketChannel ch)
  9. tuneTcpKeepalives(SocketChannel ch, int tcpKeepalive, int tcpKeepaliveCnt, int tcpKeepaliveIdle, int tcpKeepaliveIntvl)