Search in sources :

Example 41 with ServerSocket

use of java.net.ServerSocket in project spring-boot by spring-projects.

the class LiveReloadServer method start.

/**
	 * Start the livereload server and accept incoming connections.
	 * @throws IOException in case of I/O errors
	 */
public void start() throws IOException {
    synchronized (this.monitor) {
        Assert.state(!isStarted(), "Server already started");
        logger.debug("Starting live reload server on port " + this.port);
        this.serverSocket = new ServerSocket(this.port);
        this.listenThread = this.threadFactory.newThread(new Runnable() {

            @Override
            public void run() {
                acceptConnections();
            }
        });
        this.listenThread.setDaemon(true);
        this.listenThread.setName("Live Reload Server");
        this.listenThread.start();
    }
}
Also used : ServerSocket(java.net.ServerSocket)

Example 42 with ServerSocket

use of java.net.ServerSocket in project javatari by ppeccin.

the class RemoteTransmitter method start.

public void start(int port) throws IOException {
    // Open the serverSocket the first time to get errors early here
    this.port = port;
    serverSocket = new ServerSocket(port);
    updatesSender = new UpdatesSender();
    started = true;
    updatesSender.start();
}
Also used : ServerSocket(java.net.ServerSocket)

Example 43 with ServerSocket

use of java.net.ServerSocket in project jstorm by alibaba.

the class JstormYarnUtils method isPortAvailable.

/**
     * See if a port is available for listening on by trying to listen
     * on it and seeing if that works or fails.
     *
     * @param port port to listen to
     * @return true if the port was available for listening on
     */
public static boolean isPortAvailable(int port) {
    try {
        ServerSocket socket = new ServerSocket(port);
        socket.close();
        return true;
    } catch (IOException e) {
        return false;
    }
}
Also used : ServerSocket(java.net.ServerSocket)

Example 44 with ServerSocket

use of java.net.ServerSocket in project Android-Debug-Database by amitshekhariitbhu.

the class ClientServer method run.

@Override
public void run() {
    try {
        mServerSocket = new ServerSocket(mPort);
        while (mIsRunning) {
            Socket socket = mServerSocket.accept();
            mRequestHandler.handle(socket);
            socket.close();
        }
    } catch (SocketException e) {
    // The server was stopped; ignore.
    } catch (IOException e) {
        Log.e(TAG, "Web server error.", e);
    } catch (Exception ignore) {
    }
}
Also used : SocketException(java.net.SocketException) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) SocketException(java.net.SocketException) IOException(java.io.IOException)

Example 45 with ServerSocket

use of java.net.ServerSocket in project hadoop by apache.

the class TestKMS method testKMSTimeout.

/**
   * Test the configurable timeout in the KMSClientProvider.  Open up a
   * socket, but don't accept connections for it.  This leads to a timeout
   * when the KMS client attempts to connect.
   * @throws Exception
   */
@Test
public void testKMSTimeout() throws Exception {
    File confDir = getTestDir();
    Configuration conf = createBaseKMSConf(confDir);
    conf.setInt(KMSClientProvider.TIMEOUT_ATTR, 1);
    writeConf(confDir, conf);
    ServerSocket sock;
    int port;
    try {
        sock = new ServerSocket(0, 50, InetAddress.getByName("localhost"));
        port = sock.getLocalPort();
    } catch (Exception e) {
        /* Problem creating socket?  Just bail. */
        return;
    }
    URL url = new URL("http://localhost:" + port + "/kms");
    URI uri = createKMSUri(url);
    boolean caughtTimeout = false;
    try {
        KeyProvider kp = createProvider(uri, conf);
        kp.getKeys();
    } catch (SocketTimeoutException e) {
        caughtTimeout = true;
    } catch (IOException e) {
        Assert.assertTrue("Caught unexpected exception" + e.toString(), false);
    }
    caughtTimeout = false;
    try {
        KeyProvider kp = createProvider(uri, conf);
        KeyProviderCryptoExtension.createKeyProviderCryptoExtension(kp).generateEncryptedKey("a");
    } catch (SocketTimeoutException e) {
        caughtTimeout = true;
    } catch (IOException e) {
        Assert.assertTrue("Caught unexpected exception" + e.toString(), false);
    }
    caughtTimeout = false;
    try {
        KeyProvider kp = createProvider(uri, conf);
        KeyProviderCryptoExtension.createKeyProviderCryptoExtension(kp).decryptEncryptedKey(new KMSClientProvider.KMSEncryptedKeyVersion("a", "a", new byte[] { 1, 2 }, "EEK", new byte[] { 1, 2 }));
    } catch (SocketTimeoutException e) {
        caughtTimeout = true;
    } catch (IOException e) {
        Assert.assertTrue("Caught unexpected exception" + e.toString(), false);
    }
    Assert.assertTrue(caughtTimeout);
    sock.close();
}
Also used : KeyProvider(org.apache.hadoop.crypto.key.KeyProvider) Configuration(org.apache.hadoop.conf.Configuration) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) URI(java.net.URI) KMSClientProvider(org.apache.hadoop.crypto.key.kms.KMSClientProvider) LoadBalancingKMSClientProvider(org.apache.hadoop.crypto.key.kms.LoadBalancingKMSClientProvider) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) URL(java.net.URL) SocketTimeoutException(java.net.SocketTimeoutException) File(java.io.File) Test(org.junit.Test)

Aggregations

ServerSocket (java.net.ServerSocket)738 IOException (java.io.IOException)337 Socket (java.net.Socket)266 InetSocketAddress (java.net.InetSocketAddress)131 Test (org.junit.Test)118 SocketException (java.net.SocketException)56 InputStream (java.io.InputStream)51 SocketTimeoutException (java.net.SocketTimeoutException)43 OutputStream (java.io.OutputStream)41 InetAddress (java.net.InetAddress)41 BindException (java.net.BindException)28 URL (java.net.URL)28 SSLServerSocket (javax.net.ssl.SSLServerSocket)26 File (java.io.File)24 InputStreamReader (java.io.InputStreamReader)24 UnknownHostException (java.net.UnknownHostException)24 BufferedReader (java.io.BufferedReader)21 SSLSocket (javax.net.ssl.SSLSocket)21 DatagramSocket (java.net.DatagramSocket)20 ServerSocketChannel (java.nio.channels.ServerSocketChannel)16