Test.java Source code

Java tutorial

Introduction

Here is the source code for Test.java

Source

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.nio.channels.NetworkChannel;
import java.nio.channels.spi.SelectorProvider;
import java.util.Set;

public class Test {

    public static void main(String[] args) throws Exception {
        SelectorProvider provider = SelectorProvider.provider();
        NetworkChannel socketChannel = provider.openSocketChannel();
        SocketAddress address = new InetSocketAddress(3080);
        socketChannel = socketChannel.bind(address);

        Set<SocketOption<?>> socketOptions = socketChannel.supportedOptions();

        System.out.println(socketOptions.toString());
        socketChannel.setOption(StandardSocketOptions.IP_TOS, 3);
        Boolean keepAlive = socketChannel.getOption(StandardSocketOptions.SO_KEEPALIVE);
    }
}