1 jls.loader.provide('jls.net.InetSocketAddress');
  2 
  3 jls.loader.require('jls.net.InetAddress');
  4 
  5 /**
  6  * @class This class represents an Internet Protocol (IP) address and a port.
  7  */
  8 jls.net.InetSocketAddress = jls.lang.Class.create( /** @lends jls.net.InetSocketAddress.prototype */
  9 {
 10     initialize : function(addr, port) {
 11         if (addr instanceof jls.net.InetAddress) {
 12             this._addr = addr;
 13             this._port = port;
 14         } else if (typeof addr == 'string') {
 15             this._addr = jls.net.InetAddress.getByName(addr);
 16             this._port = port;
 17         } else if (typeof addr == 'number') {
 18             this._addr = INADDR_ANY; // TODO
 19             this._port = addr;
 20         } else {
 21             throw new jls.lang.Exception('Illegal argument');
 22         }
 23     },
 24     /**
 25      * Returns the InetAddress object.
 26      * 
 27      * @returns {jls.net.InetAddress} The InetAddress.
 28      */
 29     getAddress : function() {
 30         return this._addr;
 31     },
 32     /**
 33      * Returns the port number.
 34      * 
 35      * @returns {Number} The port number.
 36      */
 37     getPort : function() {
 38         return this._port;
 39     },
 40     /**
 41      * Gets the host name for this IP address.
 42      * 
 43      * @returns {String} The host name for this IP address.
 44      */
 45     getHostName : function() {
 46         return this._addr.getHostName();
 47     },
 48     /**
 49      * Gets the string representation of this socket address.
 50      * 
 51      * @returns {String} The string representation of this socket address.
 52      */
 53     toString : function() {
 54         return this.getHostName() + ':' + this.getPort();
 55     }
 56 });
 57