Package java.net

Examples of java.net.ServerSocket


      manager.setMonitor( monitor );
      manager.setSoTimeout( 10 );
      final String name = "name";
      assertEquals( "isConnected pre connect", false, manager.isConnected( name ) );
      final ServerSocketChannel channel = ServerSocketChannel.open();
      final ServerSocket serverSocket = channel.socket();
      serverSocket.setReuseAddress( true );
      final InetAddress localAddress = InetAddress.getLocalHost();
      final Random random = new Random();
      final int port = Math.abs( random.nextInt() % 5000 ) + 1024;
      final InetSocketAddress address = new InetSocketAddress( localAddress, port );
      serverSocket.bind( address );
      while ( !serverSocket.isBound() )
      {
         System.out.print( "." );
         Thread.yield();
      }
View Full Code Here


{
   public void testCreation()
      throws Exception
   {
      final String name = "name";
      final ServerSocket serverSocket = new ServerSocket();
      final MockSocketConnectionHandler handler = new MockSocketConnectionHandler();
      final AcceptorConfig config =
         new AcceptorConfig( name, serverSocket, handler );
      assertEquals( "name", name, config.getName() );
      assertEquals( "serverSocket", serverSocket, config.getServerSocket() );
View Full Code Here

      throws Exception
   {
      try
      {
         new AcceptorConfig( null,
                             new ServerSocket(),
                             new MockSocketConnectionHandler() );
      }
      catch ( final NullPointerException npe )
      {
         assertEquals( "npe.message", "name", npe.getMessage() );
View Full Code Here

      throws Exception
   {
      try
      {
         new AcceptorConfig( "name",
                             new ServerSocket(),
                             null );
      }
      catch ( NullPointerException npe )
      {
         assertEquals( "npe.message", "handler", npe.getMessage() );
View Full Code Here

                String strbuf = "HTTP/1.1 200 OK\r\n" +
                                "Date: Fri, 12 Jun 2009 05:07:45 GMT\r\n" +
                                "Server: Microsoft-IIS/5.0\r\n" +
                                "\r\n";
               
                ss = new ServerSocket(0);
                while (true) {
                    Socket socket = ss.accept();
                   
                    InputStream is = socket.getInputStream();
                    LineNumberReader lnr = new LineNumberReader(new InputStreamReader(is));
View Full Code Here

                String strbuf = "HTTP/1.1 200 OK\r\n" +
                                "Date: Fri, 12 Jun 2009 05:07:45 GMT\r\n" +
                                "Server: Microsoft-IIS/5.0\r\n" +
                                "\r\n";
               
                ss = new ServerSocket(0);
                while (true) {
                    Socket socket = ss.accept();
                   
                    InputStream is = socket.getInputStream();
                    LineNumberReader lnr = new LineNumberReader(new InputStreamReader(is));
View Full Code Here

                String strbuf = "HTTP/1.1 200 OK\r\n" +
                                "Date: Fri, 12 Jun 2009 05:07:45 GMT\r\n" +
                                "Server: Microsoft-IIS/5.0\r\n" +
                                "\r\n";
               
                ss = new ServerSocket(0);
                while (true) {
                    Socket socket = ss.accept();
                   
                    InputStream is = socket.getInputStream();
                    LineNumberReader lnr = new LineNumberReader(new InputStreamReader(is));
View Full Code Here

                String strbuf = "HTTP/1.1 200 OK\r\n" +
                                "Date: Fri, 12 Jun 2009 05:07:45 GMT\r\n" +
                                "Server: Microsoft-IIS/5.0\r\n" +
                                "\r\n";
               
                ss = new ServerSocket(0);
                while (true) {
                    Socket socket = ss.accept();
                   
                    InputStream is = socket.getInputStream();
                    LineNumberReader lnr = new LineNumberReader(new InputStreamReader(is));
View Full Code Here

      */
     ServerSocket createDataSocketActive()
         throws IOException, FTPException {

        // use any available port
        ServerSocket socket = new ServerSocket(0);

        // get the local address to which the control socket is bound.
        InetAddress localhost =  controlSock.getLocalAddress();

        // send the PORT command to the server
        setDataPort(localhost, (short)socket.getLocalPort());

        return socket;
     }
View Full Code Here

    private static boolean isPortValid(int port) {
        return port >= 1 && port <= 65535;
    }

    private static boolean isHostAndPortValid(String address, int port) {
        ServerSocket socket = null;
        try {
            if (log.isInfoEnabled())
                log.info("Testing listener on " + address + ":" + port);
            socket = new ServerSocket(port, 0, InetAddress.getByName(address));
            return true;
        } catch (IOException e) {
            log.error("Failed to setup server socket.", e);
            return false;
        } finally {
            if (socket != null) {
                try {
                    socket.close();
                } catch (Exception e) {
                }
            }
        }
    }
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.