API java : InetSocketAddress


java.net
Class InetSocketAddress

java.lang.Object
  extended by java.net.SocketAddress
      extended by java.net.InetSocketAddress
All Implemented Interfaces:
Serializable

public class InetSocketAddress
extends SocketAddress

This class implements an IP Socket Address (IP address + port number) It can also be a pair (hostname + port number), in which case an attempt will be made to resolve the hostname. If resolution fails then the address is said to be unresolved but can still be used on some circumstances like connecting through a proxy.

It provides an immutable object used by sockets for binding, connecting, or as returned values.

The wildcard is a special local IP address. It usually means "any" and can only be used for bind operations.

Since:
1.4
See Also:
Socket, ServerSocket, Serialized Form

Constructor Summary
InetSocketAddress(InetAddress addr, int port)
          Creates a socket address from an IP address and a port number.
InetSocketAddress(int port)
          Creates a socket address where the IP address is the wildcard address and the port number a specified value.
InetSocketAddress(String hostname, int port)
          Creates a socket address from a hostname and a port number.
 
Method Summary
static InetSocketAddress createUnresolved(String host, int port)
          Creates an unresolved socket address from a hostname and a port number.
 boolean equals(Object obj)
          Compares this object against the specified object.
 InetAddress getAddress()
          Gets the InetAddress.
 String getHostName()
          Gets the hostname.
 int getPort()
          Gets the port number.
 int hashCode()
          Returns a hashcode for this socket address.
 boolean isUnresolved()
          Checks whether the address has been resolved or not.
 String toString()
          Constructs a string representation of this InetSocketAddress.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InetSocketAddress

public InetSocketAddress(int port)
Creates a socket address where the IP address is the wildcard address and the port number a specified value.

A valid port value is between 0 and 65535. A port number of zero will let the system pick up an ephemeral port in a bind operation.

Parameters:
port - The port number
Throws:
IllegalArgumentException - if the port parameter is outside the specified range of valid port values.

InetSocketAddress

public InetSocketAddress(InetAddress addr,
                         int port)
Creates a socket address from an IP address and a port number.

A valid port value is between 0 and 65535. A port number of zero will let the system pick up an ephemeral port in a bind operation.

A null address will assign the wildcard address.

Parameters:
addr - The IP address
port - The port number
Throws:
IllegalArgumentException - if the port parameter is outside the specified range of valid port values.

InetSocketAddress

public InetSocketAddress(String hostname,
                         int port)
Creates a socket address from a hostname and a port number.

An attempt will be made to resolve the hostname into an InetAddress. If that attempt fails, the address will be flagged as unresolved.

If there is a security manager, its checkConnect method is called with the host name as its argument to check the permissiom to resolve it. This could result in a SecurityException.

A valid port value is between 0 and 65535. A port number of zero will let the system pick up an ephemeral port in a bind operation.

Parameters:
hostname - the Host name
port - The port number
Throws:
IllegalArgumentException - if the port parameter is outside the range of valid port values, or if the hostname parameter is null.
SecurityException - if a security manager is present and permission to resolve the host name is denied.
See Also:
isUnresolved()
Method Detail

createUnresolved

public static InetSocketAddress createUnresolved(String host,
                                                 int port)
Creates an unresolved socket address from a hostname and a port number.

No attempt will be made to resolve the hostname into an InetAddress. The address will be flagged as unresolved.

A valid port value is between 0 and 65535. A port number of zero will let the system pick up an ephemeral port in a bind operation.

Parameters:
host - the Host name
port - The port number
Returns:
a InetSocketAddress representing the unresolved socket address
Throws:
IllegalArgumentException - if the port parameter is outside the range of valid port values, or if the hostname parameter is null.
Since:
1.5
See Also:
isUnresolved()

getPort

public final int getPort()
Gets the port number.

Returns:
the port number.

getAddress

public final InetAddress getAddress()
Gets the InetAddress.

Returns:
the InetAdress or null if it is unresolved.

getHostName

public final String getHostName()
Gets the hostname.

Returns:
the hostname part of the address.

isUnresolved

public final boolean isUnresolved()
Checks whether the address has been resolved or not.

Returns:
true if the hostname couldn't be resolved into an InetAddress.

toString

public String toString()
Constructs a string representation of this InetSocketAddress. This String is constructed by calling toString() on the InetAddress and concatenating the port number (with a colon). If the address is unresolved then the part before the colon will only contain the hostname.

Overrides:
toString in class Object
Returns:
a string representation of this object.

equals

public final boolean equals(Object obj)
Compares this object against the specified object. The result is true if and only if the argument is not null and it represents the same address as this object.

Two instances of InetSocketAddress represent the same address if both the InetAddresses (or hostnames if it is unresolved) and port numbers are equal. If both addresses are unresolved, then the hostname & the port number are compared.

Overrides:
equals in class Object
Parameters:
obj - the object to compare against.
Returns:
true if the objects are the same; false otherwise.
See Also:
InetAddress.equals(java.lang.Object)

hashCode

public final int hashCode()
Returns a hashcode for this socket address.

Overrides:
hashCode in class Object
Returns:
a hash code value for this socket address.
See Also:
Object.equals(java.lang.Object), Hashtable

Ces informations proviennent du site de http://java.sun.com

Remarques

Contenu

Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :

Quels sont les motivations de cette démarche?

Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.

Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.

Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.

Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.

Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

7 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-1388
Document créé le 29/08/06 21:43, dernière modification le Vendredi 17 Juin 2011, 12:12
Source du document imprimé : http://www.gaudry.be/java-api-rf-java/net/InetSocketAddress.html Document affiché 1 fois ce mois de Juin.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
15832 documents
452 astuces.
549 niouzes.
3099 definitions.
447 membres.
8115 messages.

Document genere en :
0,59 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Réfléchis, décide et agis!

Marc Levy [Extrait de Et si c'était vrai...]
 
l'infobrol
Nous sommes le Vendredi 01 Juin 2012, 17:34, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)