java.net.ServerSocket#setSoTimeout ( )源码实例Demo

下面列出了java.net.ServerSocket#setSoTimeout ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Flink-CEPplus   文件: PythonPlanStreamer.java
private void startPython(String tmpPath, String args) throws IOException {
	String pythonBinaryPath = config.getString(PythonOptions.PYTHON_BINARY_PATH);

	try {
		Runtime.getRuntime().exec(pythonBinaryPath);
	} catch (IOException ignored) {
		throw new RuntimeException(pythonBinaryPath + " does not point to a valid python binary.");
	}
	process = Runtime.getRuntime().exec(pythonBinaryPath + " -B " + tmpPath + FLINK_PYTHON_PLAN_NAME + args);

	new Thread(new StreamPrinter(process.getInputStream())).start();
	new Thread(new StreamPrinter(process.getErrorStream())).start();

	server = new ServerSocket(0);
	server.setSoTimeout(50);

	process.getOutputStream().write("plan\n".getBytes(ConfigConstants.DEFAULT_CHARSET));
	process.getOutputStream().flush();
}
 
源代码2 项目: openjdk-8-source   文件: StreamingRetry.java
void test() throws IOException {
    ss = new ServerSocket(0);
    ss.setSoTimeout(ACCEPT_TIMEOUT);
    int port = ss.getLocalPort();

    (new Thread(this)).start();

    try {
        URL url = new URL("http://localhost:" + port + "/");
        HttpURLConnection uc = (HttpURLConnection) url.openConnection();
        uc.setDoOutput(true);
        uc.setChunkedStreamingMode(4096);
        OutputStream os = uc.getOutputStream();
        os.write("Hello there".getBytes());

        InputStream is = uc.getInputStream();
        is.close();
    } catch (IOException expected) {
        //expected.printStackTrace();
    } finally {
        ss.close();
    }
}
 
源代码3 项目: netbeans   文件: ServerThread.java
private boolean createServerSocket(DebugSession debugSession) {
    synchronized (ServerThread.class) {
        try {
            myPort = debugSession.getOptions().getPort();
            myServer = new ServerSocket(myPort);
            myServer.setSoTimeout(TIMEOUT);
            myServer.setReuseAddress(true);
        } catch (IOException e) {
            String mesg = NbBundle.getMessage(ServerThread.class, PORT_OCCUPIED);
            mesg = MessageFormat.format(mesg, myPort);
            NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(mesg, JOptionPane.YES_NO_OPTION);
            Object choice = DialogDisplayer.getDefault().notify(descriptor);
            if (choice.equals(JOptionPane.YES_OPTION)) {
                Utils.openPhpOptionsDialog();
            }
            log(e);
            return false;
        }
        return true;
    }
}
 
源代码4 项目: openjdk-8   文件: SelectFdsLimit.java
public static void main(String [] args) throws IOException, FileNotFoundException {

        //The bug 8021820 is a Mac specific and because of that test will pass on all
        //other platforms
        if (!System.getProperty("os.name").contains("OS X")) {
           return;
        }

        //Create test directory with test files
        prepareTestEnv();

        //Consume FD ids for this java process to overflow the 1024
        openFiles(FDTOOPEN,new File(TESTFILE));

        //Wait for incoming connection and make the select() used in java.net
        //classes fail the limitation on FDSET_SIZE
        ServerSocket socket = new ServerSocket(0);

        //Set the minimal timeout, no one is
        //going to connect to this server socket
        socket.setSoTimeout(1);

        // The accept() call will throw SocketException if the
        // select() has failed due to limitation on fds size,
        // indicating test failure. A SocketTimeoutException
        // is expected, so it is caught and ignored, and the test
        // passes.
        try {
           socket.accept();
        } catch (SocketTimeoutException e) { }
    }
 
源代码5 项目: TencentKona-8   文件: SelectFdsLimit.java
public static void main(String [] args) throws IOException, FileNotFoundException {

        //The bug 8021820 is a Mac specific and because of that test will pass on all
        //other platforms
        if (!System.getProperty("os.name").contains("OS X")) {
           return;
        }

        //Create test directory with test files
        prepareTestEnv();

        //Consume FD ids for this java process to overflow the 1024
        openFiles(FDTOOPEN,new File(TESTFILE));

        //Wait for incoming connection and make the select() used in java.net
        //classes fail the limitation on FDSET_SIZE
        ServerSocket socket = new ServerSocket(0);

        //Set the minimal timeout, no one is
        //going to connect to this server socket
        socket.setSoTimeout(1);

        // The accept() call will throw SocketException if the
        // select() has failed due to limitation on fds size,
        // indicating test failure. A SocketTimeoutException
        // is expected, so it is caught and ignored, and the test
        // passes.
        try {
           socket.accept();
        } catch (SocketTimeoutException e) { }
    }
 
protected static ServerSocket openServerSocket(final InetAddress address, final int port, final boolean reuseAddress, final int socketTimeout)
  throws IOException
{
  final ServerSocket serverSocket = new ServerSocket();
  serverSocket.setReuseAddress(reuseAddress);
  serverSocket.setSoTimeout(socketTimeout);
  serverSocket.bind(new InetSocketAddress(address, port));
  return serverSocket;
}
 
源代码7 项目: jdk8u60   文件: SelectFdsLimit.java
public static void main(String [] args) throws IOException, FileNotFoundException {

        //The bug 8021820 is a Mac specific and because of that test will pass on all
        //other platforms
        if (!System.getProperty("os.name").contains("OS X")) {
           return;
        }

        //Create test directory with test files
        prepareTestEnv();

        //Consume FD ids for this java process to overflow the 1024
        openFiles(FDTOOPEN,new File(TESTFILE));

        //Wait for incoming connection and make the select() used in java.net
        //classes fail the limitation on FDSET_SIZE
        ServerSocket socket = new ServerSocket(0);

        //Set the minimal timeout, no one is
        //going to connect to this server socket
        socket.setSoTimeout(1);

        // The accept() call will throw SocketException if the
        // select() has failed due to limitation on fds size,
        // indicating test failure. A SocketTimeoutException
        // is expected, so it is caught and ignored, and the test
        // passes.
        try {
           socket.accept();
        } catch (SocketTimeoutException e) { }
    }
 
源代码8 项目: hottub   文件: SelectFdsLimit.java
public static void main(String [] args) throws IOException, FileNotFoundException {

        //The bug 8021820 is a Mac specific and because of that test will pass on all
        //other platforms
        if (!System.getProperty("os.name").contains("OS X")) {
           return;
        }

        //Create test directory with test files
        prepareTestEnv();

        //Consume FD ids for this java process to overflow the 1024
        openFiles(FDTOOPEN,new File(TESTFILE));

        //Wait for incoming connection and make the select() used in java.net
        //classes fail the limitation on FDSET_SIZE
        ServerSocket socket = new ServerSocket(0);

        //Set the minimal timeout, no one is
        //going to connect to this server socket
        socket.setSoTimeout(1);

        // The accept() call will throw SocketException if the
        // select() has failed due to limitation on fds size,
        // indicating test failure. A SocketTimeoutException
        // is expected, so it is caught and ignored, and the test
        // passes.
        try {
           socket.accept();
        } catch (SocketTimeoutException e) { }
    }
 
源代码9 项目: openjdk-jdk9   文件: StreamingRetry.java
void test(String method) throws Exception {
    ss = new ServerSocket(0);
    ss.setSoTimeout(ACCEPT_TIMEOUT);
    int port = ss.getLocalPort();

    Thread otherThread = new Thread(this);
    otherThread.start();

    try {
        URL url = new URL("http://localhost:" + port + "/");
        HttpURLConnection uc = (HttpURLConnection) url.openConnection();
        uc.setDoOutput(true);
        if (method != null)
            uc.setRequestMethod(method);
        uc.setChunkedStreamingMode(4096);
        OutputStream os = uc.getOutputStream();
        os.write("Hello there".getBytes());

        InputStream is = uc.getInputStream();
        is.close();
    } catch (IOException expected) {
        //expected.printStackTrace();
    } finally {
        ss.close();
        otherThread.join();
    }
}
 
源代码10 项目: tomcatsrc   文件: JSSESocketFactory.java
/**
 * Checks that the certificate is compatible with the enabled cipher suites.
 * If we don't check now, the JIoEndpoint can enter a nasty logging loop.
 * See bug 45528.
 */
private void checkConfig() throws IOException {
    // Create an unbound server socket
    ServerSocket socket = sslProxy.createServerSocket();
    initServerSocket(socket);

    try {
        // Set the timeout to 1ms as all we care about is if it throws an
        // SSLException on accept.
        socket.setSoTimeout(1);

        socket.accept();
        // Will never get here - no client can connect to an unbound port
    } catch (SSLException ssle) {
        // SSL configuration is invalid. Possibly cert doesn't match ciphers
        IOException ioe = new IOException(sm.getString(
                "jsse.invalid_ssl_conf", ssle.getMessage()));
        ioe.initCause(ssle);
        throw ioe;
    } catch (Exception e) {
        /*
         * Possible ways of getting here
         * socket.accept() throws a SecurityException
         * socket.setSoTimeout() throws a SocketException
         * socket.accept() throws some other exception (after a JDK change)
         *      In these cases the test won't work so carry on - essentially
         *      the behaviour before this patch
         * socket.accept() throws a SocketTimeoutException
         *      In this case all is well so carry on
         */
    } finally {
        // Should be open here but just in case
        if (!socket.isClosed()) {
            socket.close();
        }
    }

}
 
源代码11 项目: jdk8u_jdk   文件: SelectFdsLimit.java
public static void main(String [] args) throws IOException, FileNotFoundException {

        //The bug 8021820 is a Mac specific and because of that test will pass on all
        //other platforms
        if (!System.getProperty("os.name").contains("OS X")) {
           return;
        }

        //Create test directory with test files
        prepareTestEnv();

        //Consume FD ids for this java process to overflow the 1024
        openFiles(FDTOOPEN,new File(TESTFILE));

        //Wait for incoming connection and make the select() used in java.net
        //classes fail the limitation on FDSET_SIZE
        ServerSocket socket = new ServerSocket(0);

        //Set the minimal timeout, no one is
        //going to connect to this server socket
        socket.setSoTimeout(1);

        // The accept() call will throw SocketException if the
        // select() has failed due to limitation on fds size,
        // indicating test failure. A SocketTimeoutException
        // is expected, so it is caught and ignored, and the test
        // passes.
        try {
           socket.accept();
        } catch (SocketTimeoutException e) { }
    }
 
源代码12 项目: rcrs-server   文件: ConnectionManager.java
/**
   Listen for connections on a particular port.
   @param port The port to listen on.
   @param registry The registry to install in new connections.
   @param listener A ConnectionManagerListener that will be informed of new connections.
   @throws IOException If there is a problem listening on the port.
*/
public void listen(int port, Registry registry, ConnectionManagerListener listener) throws IOException {
    synchronized (lock) {
        if (shutdown) {
            throw new IOException("Connection manager has been shut down");
        }
        Logger.info("Listening for connections on port " + port);
        ServerSocket socket = new ServerSocket(port);
        socket.setSoTimeout(1000);
        socket.setReuseAddress(true);
        Reader r = new Reader(socket, registry, listener);
        readers.add(r);
        r.start();
    }
}
 
源代码13 项目: jdk8u-jdk   文件: SelectFdsLimit.java
public static void main(String [] args) throws IOException, FileNotFoundException {

        //The bug 8021820 is a Mac specific and because of that test will pass on all
        //other platforms
        if (!System.getProperty("os.name").contains("OS X")) {
           return;
        }

        //Create test directory with test files
        prepareTestEnv();

        //Consume FD ids for this java process to overflow the 1024
        openFiles(FDTOOPEN,new File(TESTFILE));

        //Wait for incoming connection and make the select() used in java.net
        //classes fail the limitation on FDSET_SIZE
        ServerSocket socket = new ServerSocket(0);

        //Set the minimal timeout, no one is
        //going to connect to this server socket
        socket.setSoTimeout(1);

        // The accept() call will throw SocketException if the
        // select() has failed due to limitation on fds size,
        // indicating test failure. A SocketTimeoutException
        // is expected, so it is caught and ignored, and the test
        // passes.
        try {
           socket.accept();
        } catch (SocketTimeoutException e) { }
    }
 
源代码14 项目: tomcatsrc   文件: SocketProperties.java
public void setProperties(ServerSocket socket) throws SocketException{
    if (rxBufSize != null)
        socket.setReceiveBufferSize(rxBufSize.intValue());
    if (performanceConnectionTime != null && performanceLatency != null &&
            performanceBandwidth != null)
        socket.setPerformancePreferences(
                performanceConnectionTime.intValue(),
                performanceLatency.intValue(),
                performanceBandwidth.intValue());
    if (soReuseAddress != null)
        socket.setReuseAddress(soReuseAddress.booleanValue());
    if (soTimeout != null && soTimeout.intValue() >= 0)
        socket.setSoTimeout(soTimeout.intValue());
}
 
源代码15 项目: jsmpp   文件: ServerSocketConnectionFactory.java
public ServerConnection listen(int port, int timeout) throws IOException {
    ServerSocket ss = new ServerSocket(port);
    ss.setSoTimeout(timeout);
    return new ServerSocketConnection(ss);
}
 
public ServerConnection listen(int port, int timeout) throws IOException {
  ServerSocket serverSocket = sslServerSocketFactory.createServerSocket(port);
  serverSocket.setSoTimeout(timeout);
  return new ServerSocketConnection(serverSocket);
}
 
源代码17 项目: jsmpp   文件: SSLServerSocketConnectionFactory.java
public ServerConnection listen(int port, int timeout) throws IOException {
  ServerSocketFactory serverSocketFactory = SSLServerSocketFactory.getDefault();
  ServerSocket serverSocket = serverSocketFactory.createServerSocket(port);
  serverSocket.setSoTimeout(timeout);
  return new ServerSocketConnection(serverSocket);
}
 
源代码18 项目: rxjava2-extras   文件: FlowableServerSocket.java
private static ServerSocket createServerSocket(Callable<? extends ServerSocket> serverSocketCreator, long timeoutMs)
        throws Exception {
    ServerSocket s = serverSocketCreator.call();
    s.setSoTimeout((int) timeoutMs);
    return s;
}
 
源代码19 项目: rxjava-extras   文件: ObservableServerSocket.java
private static ServerSocket createServerSocket(
        Func0<? extends ServerSocket> serverSocketCreator, long timeoutMs) throws IOException {
    ServerSocket s = serverSocketCreator.call();
    s.setSoTimeout((int) timeoutMs);
    return s;
}
 
源代码20 项目: jsflight   文件: JMeterDaemon.java
/**
 * Create a new Daemon with the specified port and target, using the
 * specified class to handle individual requests.
 *
 * @param port       the port to listen on.
 * @param target     the target which will receive the generated JMeter test
 *                   components.
 * @param proxyClass the proxy class to use to handle individual requests. This
 *                   class must be the {@link Proxy} class or a subclass.
 * @throws IOException              if an I/O error occurs opening the socket
 * @throws IllegalArgumentException if <code>port</code> is outside the allowed range from <code>0</code> to <code>65535</code>
 * @throws SocketException          when something is wrong on the underlying protocol layer
 */
public JMeterDaemon(int port, JMeterProxyControl target, Class<? extends JMeterProxy> proxyClass)
        throws IOException
{
    super("HTTP Proxy Daemon");
    this.target = target;
    this.daemonPort = port;
    this.proxyClass = proxyClass;
    LOG.info("Creating Daemon Socket on port: " + daemonPort);
    mainSocket = new ServerSocket(daemonPort);
    mainSocket.setSoTimeout(ACCEPT_TIMEOUT);
}