Package java.net

Examples of java.net.ServerSocket


        ((Short)list.elementAt(i)).shortValue();
    }

    // Create the socket here in order to throw an exception
    // if the socket can't be created (even if firstTime is false).
    ServerSocket serverSocket = new ServerSocket(port);

    int poolSize = AgentServer.getInteger(JndiServer.POOL_SIZE_PROP, JndiServer.DEFAULT_POOL_SIZE).intValue();

    int timeout = AgentServer.getInteger(JndiServer.SO_TIMEOUT_PROP, JndiServer.DEFAULT_SO_TIMEOUT).intValue();
View Full Code Here


   
    int port = Integer.parseInt(args);

    // Create the socket here in order to throw an exception
    // if the socket can't be created (even if firstTime is false).
    ServerSocket serverSocket = new ServerSocket(port);

    int poolSize = AgentServer.getInteger(POOL_SIZE_PROP, DEFAULT_POOL_SIZE).intValue();

    int timeout = AgentServer.getInteger(SO_TIMEOUT_PROP, DEFAULT_SO_TIMEOUT).intValue();
View Full Code Here

    private void testWrongServer() throws Exception {
        // try to connect when the server is not running
        assertThrows(ErrorCode.CONNECTION_BROKEN_1, this).
                getConnection("jdbc:h2:tcp://localhost:9001/test");
        final ServerSocket serverSocket = new ServerSocket(9001);
        Task task = new Task() {
            public void call() throws Exception {
                Socket socket = serverSocket.accept();
                byte[] data = new byte[1024];
                data[0] = 'x';
                socket.getOutputStream().write(data);
                socket.close();
            }
        };
        task.execute();
        Thread.sleep(100);
        try {
            getConnection("jdbc:h2:tcp://localhost:9001/test");
            fail();
        } catch (SQLException e) {
            assertEquals(ErrorCode.CONNECTION_BROKEN_1, e.getErrorCode());
        }
        serverSocket.close();
        task.get();
    }
View Full Code Here

   * @param backlog   the maximum length of the queue, or 0 to use the default value.
   *
   * @see ServerSocketFactory#createServerSocket(java.net.InetAddress, int, int)
   */
  public ServerSocket createServerSocket(int port, int backlog) throws IOException {
    return new ServerSocket(port, backlog);
  }
View Full Code Here

   * @see ServerSocketFactory#createServerSocket(int, int, InetAddress)
   */
  public ServerSocket createServerSocket(int port,
                                         int backlog,
                                         InetAddress addr) throws IOException {
    return new ServerSocket(port, backlog, addr);
  }
View Full Code Here

        testFrequentConnections(true, 100);
        testFrequentConnections(false, 1000);
    }

    private void testFrequentConnections(boolean ssl, int count) throws Exception {
        final ServerSocket serverSocket = NetUtils.createServerSocket(PORT, ssl);
        final AtomicInteger counter = new AtomicInteger(count);
        Task serverThread = new Task() {
            public void call() {
                while (!stop) {
                    try {
                        Socket socket = serverSocket.accept();
                        // System.out.println("opened " + counter);
                        socket.close();
                    } catch (Exception e) {
                        // ignore
                    }
                }
                // System.out.println("stopped ");

            }
        };
        serverThread.execute();
        try {
            Set<ConnectWorker> workers = new HashSet<ConnectWorker>();
            for (int i = 0; i < WORKER_COUNT; i++) {
                workers.add(new ConnectWorker(ssl, counter));
            }
            // ensure the server is started
            Thread.sleep(100);
            for (ConnectWorker worker : workers) {
                worker.start();
            }
            for (ConnectWorker worker : workers) {
                worker.join();
                Exception e = worker.getException();
                if (e != null) {
                    e.printStackTrace();
                }
            }
        } finally {
            try {
                serverSocket.close();
            } catch (Exception e) {
                // ignore
            }
            serverThread.get();
        }
View Full Code Here

   */
  protected ServerSocket createServerSocket(int port, int backlog, String address) throws Exception {
    if (logger.isLoggable(BasicLevel.DEBUG))
      logger.log(BasicLevel.DEBUG, "TcpProxyService.createServerSocket(" + port + ',' + backlog + ',' + address + ')');
   
    ServerSocket serverSocket;
    // TODO (AF): Use the ServerSocketFactory
    if (address.equals("0.0.0.0")) {
      serverSocket = new ServerSocket(port, backlog);
    } else {
      serverSocket = new ServerSocket(port, backlog, InetAddress.getByName(address));
    }
   
    if (logger.isLoggable(BasicLevel.DEBUG))
      logger.log(BasicLevel.DEBUG, "TcpProxyService.createServerSocket serverSocket = " + serverSocket);
   
View Full Code Here

   * @return    a SSL server socket bound to the specified port.
   *
   * @exception IOException  for networking errors
   */
  ServerSocket createServerSocket(int port) throws IOException {
    ServerSocket serverSocket =
      getServerSocketFactory().createServerSocket(port, backlog, inLocalAddr);
    ((SSLServerSocket) serverSocket).setNeedClientAuth(false);

    return serverSocket;
  }
View Full Code Here

        }
    }

    private void listen(int port) throws IOException {
        new Thread(this).start();
        ServerSocket serverSocket = new ServerSocket(port);
        System.out.println("Listening on " + serverSocket.toString());
        long time;
        maxValue = 0;
        while (true) {
            Socket socket = serverSocket.accept();
            DataInputStream in = new DataInputStream(socket.getInputStream());
            System.out.println("Connected");
            time = System.currentTimeMillis();
            try {
                while (true) {
View Full Code Here

    protected String getProtocol() {
        return "https";
    }

    protected ServerSocket createSocket(int port) throws IOException {
        ServerSocket serverSocket = super.createSocket(port);
        String cipherSuites = CIPHERS_OPTION.getProperty( server, getName() );
        if( cipherSuites != null ) {
            ((SSLServerSocket)serverSocket).setEnabledCipherSuites( cipherSuites.split(",") );
        }
View Full Code Here

TOP

Related Classes of java.net.ServerSocket

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.