Example usage for java.net ServerSocket ServerSocket

List of usage examples for java.net ServerSocket ServerSocket

Introduction

In this page you can find the example usage for java.net ServerSocket ServerSocket.

Prototype

public ServerSocket(int port) throws IOException 

Source Link

Document

Creates a server socket, bound to the specified port.

Usage

From source file:ch.sourcepond.maven.plugin.jenkins.it.utils.Simulator.java

/**
 * @throws IOException/*  w  w w.j  a v a  2 s.  co m*/
 */
public Simulator() throws IOException {
    try (ServerSocket s = new ServerSocket(0)) {
        port = s.getLocalPort();
    }
}

From source file:it.geosolutions.geostore.services.rest.SecurityTest.java

/**
 * Checks if a network host / port is already occupied.
 * //ww w . j  av  a2s  .co m
 * @param host
 * @param port
 * @return
 */
private static boolean portIsBusy(String host, int port) {
    ServerSocket ss = null;
    DatagramSocket ds = null;
    try {
        ss = new ServerSocket(port);
        ss.setReuseAddress(true);
        ds = new DatagramSocket(port);
        ds.setReuseAddress(true);
        return false;
    } catch (IOException e) {
    } finally {
        if (ds != null) {
            ds.close();
        }
        if (ss != null) {
            try {
                ss.close();
            } catch (IOException e) {
                /* should not be thrown */
            }
        }
    }
    return true;
}

From source file:com.l2jfree.loginserver.thread.FloodProtectedListener.java

public FloodProtectedListener(String listenIp, int port) {
    try {/*from  w w  w.  j  a v a  2 s .  c o  m*/
        if (listenIp.equals("*"))
            _serverSocket = new ServerSocket(port);
        else
            _serverSocket = new ServerSocket(port, 50, InetAddress.getByName(listenIp));
    } catch (IOException e) {
        throw new RuntimeException("Error creating ServerSocket: ", e);
    }
}

From source file:org.apache.cxf.dosgi.singlebundle.AggregatedActivatorTest.java

@Override
protected void setUp() throws Exception {
    oldDefaultPort = AggregatedActivator.DEFAULT_HTTP_PORT;
    // Change the default port to one that we know is available
    ServerSocket s = new ServerSocket(0);
    int availablePort = s.getLocalPort();
    s.close();//  w  w w . j  av a2 s. co  m
    AggregatedActivator.DEFAULT_HTTP_PORT = "" + availablePort;

    savedProps = new HashMap<Object, Object>(System.getProperties());
    super.setUp();
}

From source file:httpscheduler.GenericRequestListenerThread.java

public GenericRequestListenerThread(final int port, final HttpService httpService,
        final SSLServerSocketFactory sf) throws IOException {

    this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE;
    this.serversocket = sf != null ? sf.createServerSocket(port) : new ServerSocket(port);
    this.httpService = httpService;
    // only 4 connections can run concurrently
    connectionHandlerExecutor = Executors.newFixedThreadPool(1000);
    //System.out.println("Request Listener Thread created");
}

From source file:io.crate.testing.Utils.java

static int randomAvailablePort(int from, int to) {
    int repeat = 5;
    while (repeat > 0)
        try {//w  w  w  .j  av a2 s . co m
            int port = ThreadLocalRandom.current().nextInt(from, to + 1);
            ServerSocket socket = new ServerSocket(port);
            socket.close();
            return port;
        } catch (IOException ignored) {
            repeat--;
        }
    throw new RuntimeException("no free port found");
}

From source file:httpscheduler.LateBindingRequestListenerThread.java

public LateBindingRequestListenerThread(final int port, final HttpService httpService,
        final SSLServerSocketFactory sf) throws IOException {

    this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE;
    this.serversocket = sf != null ? sf.createServerSocket(port) : new ServerSocket(port);
    this.httpService = httpService;
    // only 4 connections can run concurrently
    connectionHandlerExecutor = Executors.newFixedThreadPool(22);
    System.out.println("Request Listener Thread created");
}

From source file:com.cloudera.branchreduce.impl.thrift.VassalMain.java

private void initialize(String[] args) throws Exception {
    this.hostname = InetAddress.getLocalHost().getHostName();
    this.socket = new ServerSocket(0);
    this.job = new BranchReduceJob(false, getConf());
    this.masterHostname = args[0];
    this.masterPort = Integer.valueOf(args[1]);
}

From source file:com.hierynomus.smbj.server.StubSmbServer.java

public void start() {
    try {/* w w w  .  j  a  v a 2s .co m*/
        socket = new ServerSocket(port);
        thread = new Thread(new Runnable() {
            @Override
            public void run() {
                runServer();
            }
        });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:LCModels.MessageListener.java

public void setPort(int port) {
    try {/*  w  w  w  . j a  va  2s. c om*/
        server = new ServerSocket(port);
    } catch (IOException ex) {
        Logger.getLogger(MessageListener.class.getName()).log(Level.SEVERE, null, ex);
    }
}