public interface SocketOptions
Interface of methods to get/set socket options. This interface is implemented by: SocketImpl and DatagramSocketImpl. Subclasses of these should override the methods of this interface in order to support their own options.
The methods and constants which specify options in this interface are for implementation only. If you're not subclassing SocketImpl or DatagramSocketImpl, you won't use these directly. There are type-safe methods to get/set each of these options in Socket, ServerSocket, DatagramSocket and MulticastSocket.
| Field Summary | |
|---|---|
static int |
IP_MULTICAST_IF
Set which outgoing interface on which to send multicast packets. |
static int |
IP_MULTICAST_IF2
Same as above. |
static int |
IP_MULTICAST_LOOP
This option enables or disables local loopback of multicast datagrams. |
static int |
IP_TOS
This option sets the type-of-service or traffic class field in the IP header for a TCP or UDP socket. |
static int |
SO_BINDADDR
Fetch the local address binding of a socket (this option cannot be "set" only "gotten", since sockets are bound at creation time, and so the locally bound address cannot be changed). |
static int |
SO_BROADCAST
Sets SO_BROADCAST for a socket. |
static int |
SO_KEEPALIVE
When the keepalive option is set for a TCP socket and no data has been exchanged across the socket in either direction for 2 hours (NOTE: the actual value is implementation dependent), TCP automatically sends a keepalive probe to the peer. |
static int |
SO_LINGER
Specify a linger-on-close timeout. |
static int |
SO_OOBINLINE
When the OOBINLINE option is set, any TCP urgent data received on the socket will be received through the socket input stream. |
static int |
SO_RCVBUF
Set a hint the size of the underlying buffers used by the platform for incoming network I/O. |
static int |
SO_REUSEADDR
Sets SO_REUSEADDR for a socket. |
static int |
SO_SNDBUF
Set a hint the size of the underlying buffers used by the platform for outgoing network I/O. |
static int |
SO_TIMEOUT
Set a timeout on blocking Socket operations: |
static int |
TCP_NODELAY
Disable Nagle's algorithm for this connection. |
| Method Summary | |
|---|---|
Object |
getOption(int optID)
Fetch the value of an option. |
void |
setOption(int optID,
Object value)
Enable/disable the option specified by optID. |
| Field Detail |
|---|
static final int TCP_NODELAY
Valid for TCP only: SocketImpl.
static final int SO_BINDADDR
This option must be specified in the constructor.
Valid for: SocketImpl, DatagramSocketImpl
static final int SO_REUSEADDR
Valid for: DatagramSocketImpl
static final int SO_BROADCAST
static final int IP_MULTICAST_IF
Valid for Multicast: DatagramSocketImpl
static final int IP_MULTICAST_IF2
static final int IP_MULTICAST_LOOP
static final int IP_TOS
static final int SO_LINGER
Valid only for TCP: SocketImpl
static final int SO_TIMEOUT
ServerSocket.accept(); SocketInputStream.read(); DatagramSocket.receive();
The option must be set prior to entering a blocking operation to take effect. If the timeout expires and the operation would continue to block, java.io.InterruptedIOException is raised. The Socket is not closed in this case.
Valid for all sockets: SocketImpl, DatagramSocketImpl
static final int SO_SNDBUF
static final int SO_RCVBUF
static final int SO_KEEPALIVE
static final int SO_OOBINLINE
| Method Detail |
|---|
void setOption(int optID,
Object value)
throws SocketException
SocketImpl s;
...
s.setOption(SO_LINGER, new Integer(10));
// OK - set SO_LINGER w/ timeout of 10 sec.
s.setOption(SO_LINGER, new Double(10));
// ERROR - expects java.lang.Integer
If the requested option is binary, it can be set using this method by
a java.lang.Boolean:
s.setOption(TCP_NODELAY, new Boolean(true));
// OK - enables TCP_NODELAY, a binary option
s.setOption(TCP_NODELAY, new Boolean(false));
// OK - disables TCP_NODELAY
s.setOption(SO_LINGER, new Boolean(false));
// OK - disables SO_LINGER
optID - identifies the optionvalue - the parameter of the socket option
SocketException - if the option is unrecognized,
the socket is closed, or some low-level error occurredgetOption(int)Object getOption(int optID) throws SocketException
SocketImpl s;
...
Boolean noDelay = (Boolean)(s.getOption(TCP_NODELAY));
if (noDelay.booleanValue()) {
// true if TCP_NODELAY is enabled...
...
}
For options that take a particular type as a parameter, getOption(int) will return the paramter's value, else it will return java.lang.Boolean(false):
Object o = s.getOption(SO_LINGER);
if (o instanceof Integer) {
System.out.print("Linger time is " + ((Integer)o).intValue());
} else {
// the true type of o is java.lang.Boolean(false);
}
optID - an int identifying the option to fetch
SocketException - if the socket is closed
SocketException - if optID is unknown along the
protocol stack (including the SocketImpl)setOption(int, java.lang.Object)Ces informations proviennent du site de http://java.sun.com
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 :
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.
Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.
6 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.
Recherche (afficher)
Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
Citation (masquer)