src/main/java/pityoulish/tutorial/TutorialCommandHandler.java
protected int handleIsLocalCmd(String hostname)
   {
     // this may perform a DNS lookup, with all sorts of resulting problems
     InetSocketAddress isa = new InetSocketAddress(hostname, 0);

     int result = -1;
     try {
       // if the address is local, we can bind a socket to it
       // PYL:keep
       Missing.here("bind a socket to a hostname");
       Missing.pretend(IOException.class);
       // PYL:cut
       Socket so = new Socket();
       so.bind(isa);
       // PYL:end

       result = 0;
       System.out.println(Catalog.HOST_IS_LOCAL_1.format(hostname));
       // The ephemereal port chosen for binding is now allocated and
       // cannot be used elsewhere for some time, typically minutes.

     } catch (IOException iox) {
       System.out.println(iox.toString());
       result = -1;
       System.out.println(Catalog.HOST_NOT_LOCAL_1.format(hostname));
     }

     return result;
   }
/**
   * Checks whether a hostname refers to the local host.
   *
   * @param hostname    the hostname or string-encoded IP address to check
   *
   * @return    0 if the argument is the local host, -1 if it isn't
   */
Checks whether a hostname refers to the local host.
@param hostname    the hostname or string-encoded IP address to check

@return    0 if the argument is the local host, -1 if it isn't
Checks whether a hostname refers to the local host . @param hostname the hostname or string - encoded IP address to check @return 0 if the argument is the local host - 1 if it isn ' t
protected int handleIsLocalCmd(String hostname)
   {
     InetSocketAddress isa = new InetSocketAddress(hostname, 0);
     int result = -1;
     try {
       Missing.here("bind a socket to a hostname");
       Missing.pretend(IOException.class);
       Socket so = new Socket();
       so.bind(isa);
       result = 0;
       System.out.println(Catalog.HOST_IS_LOCAL_1.format(hostname));
     } catch (IOException iox) {
       System.out.println(iox.toString());
       result = -1;
       System.out.println(Catalog.HOST_NOT_LOCAL_1.format(hostname));
     }
     return result;
   }
protected int handleIsLocalCmd ( String hostname ) { InetSocketAddress isa = new InetSocketAddress ( hostname , 0 ) ; int result = - 1 ; try { Missing . here ( "bind a socket to a hostname" ) ; Missing . pretend ( IOException . class ) ; Socket so = new Socket ( ) ; so . bind ( isa ) ; result = 0 ; System . out . println ( Catalog . HOST_IS_LOCAL_1 . format ( hostname ) ) ; } catch ( IOException iox ) { System . out . println ( iox . toString ( ) ) ; result = - 1 ; System . out . println ( Catalog . HOST_NOT_LOCAL_1 . format ( hostname ) ) ; } return result ; }
Checks whether a hostname refers to the local host.
Checks whether a hostname refers to the local host .
// this may perform a DNS lookup, with all sorts of resulting problems // if the address is local, we can bind a socket to it // PYL:keep // PYL:cut // PYL:end // The ephemereal port chosen for binding is now allocated and // cannot be used elsewhere for some time, typically minutes.