Example usage for javax.net ServerSocketFactory createServerSocket

List of usage examples for javax.net ServerSocketFactory createServerSocket

Introduction

In this page you can find the example usage for javax.net ServerSocketFactory createServerSocket.

Prototype

public ServerSocket createServerSocket() throws IOException 

Source Link

Document

Returns an unbound server socket.

Usage

From source file:org.apache.geode.internal.net.SocketCreator.java

private ServerSocket createServerSocket(int nport, int backlog, InetAddress bindAddr, int socketBufferSize,
        boolean sslConnection) throws IOException {
    printConfig();//from  w w  w  . j  a v a2s. c om
    if (sslConnection) {
        if (this.sslContext == null) {
            throw new GemFireConfigException("SSL not configured correctly, Please look at previous error");
        }
        ServerSocketFactory ssf = this.sslContext.getServerSocketFactory();
        SSLServerSocket serverSocket = (SSLServerSocket) ssf.createServerSocket();
        serverSocket.setReuseAddress(true);
        // If necessary, set the receive buffer size before binding the socket so
        // that large buffers will be allocated on accepted sockets (see
        // java.net.ServerSocket.setReceiverBufferSize javadocs)
        if (socketBufferSize != -1) {
            serverSocket.setReceiveBufferSize(socketBufferSize);
        }
        serverSocket.bind(new InetSocketAddress(bindAddr, nport), backlog);
        finishServerSocket(serverSocket);
        return serverSocket;
    } else {
        // log.info("Opening server socket on " + nport, new Exception("SocketCreation"));
        ServerSocket result = new ServerSocket();
        result.setReuseAddress(true);
        // If necessary, set the receive buffer size before binding the socket so
        // that large buffers will be allocated on accepted sockets (see
        // java.net.ServerSocket.setReceiverBufferSize javadocs)
        if (socketBufferSize != -1) {
            result.setReceiveBufferSize(socketBufferSize);
        }
        try {
            result.bind(new InetSocketAddress(bindAddr, nport), backlog);
        } catch (BindException e) {
            BindException throwMe = new BindException(
                    LocalizedStrings.SocketCreator_FAILED_TO_CREATE_SERVER_SOCKET_ON_0_1
                            .toLocalizedString(new Object[] { bindAddr, Integer.valueOf(nport) }));
            throwMe.initCause(e);
            throw throwMe;
        }
        return result;
    }
}