Java SocketChannel createServerSocketChannel(int aPort, String aHostname)

Here you can find the source of createServerSocketChannel(int aPort, String aHostname)

Description

Creates a ServerSocketChannel

License

Apache License

Parameter

Parameter Description
aPort a parameter
aHostname a parameter

Exception

Parameter Description
IOException an exception

Return

The ServerSocketChannel instance

Declaration

public static ServerSocketChannel createServerSocketChannel(int aPort,
        String aHostname) throws IOException 

Method Source Code

//package com.java2s;
//   Licensed under the Apache License, Version 2.0 (the "License");

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;

import java.nio.channels.ServerSocketChannel;

public class Main {
    /**/* www. j a v a  2 s . c  o  m*/
     * Creates a ServerSocketChannel
     *
     * @param aPort
     * @param aHostname
     * @return The ServerSocketChannel instance
     * @throws IOException
     */
    public static ServerSocketChannel createServerSocketChannel(int aPort,
            String aHostname) throws IOException {
        ServerSocketChannel lServer = ServerSocketChannel.open();
        lServer.configureBlocking(false);

        if (null == aHostname) {
            lServer.socket().bind(new InetSocketAddress(aPort));
        } else {
            lServer.socket().bind(
                    new InetSocketAddress(InetAddress.getByName(aHostname),
                            aPort));
        }
        return lServer;
    }
}

Related

  1. enhanceExceptionWithAddress(final SocketChannel channel, final IOException e)
  2. finishConnect(SocketChannel socketChannel)
  3. getConnectedSocketChannel(InetAddress host, int port, int timeout)
  4. getSocketAddress(SocketChannel socketChannel)