|
|||||||||
| Home >> All >> org >> apache >> commons >> [ net overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.commons.net
Class DatagramSocketClient

java.lang.Objectorg.apache.commons.net.DatagramSocketClient
- Direct Known Subclasses:
- CharGenUDPClient, DaytimeUDPClient, DiscardUDPClient, TimeUDPClient
- public abstract class DatagramSocketClient
- extends java.lang.Object
The DatagramSocketClient provides the basic operations that are required of client objects accessing datagram sockets. It is meant to be subclassed to avoid having to rewrite the same code over and over again to open a socket, close a socket, set timeouts, etc. Of special note is the setDatagramSocketFactory 55 method, which allows you to control the type of DatagramSocket the DatagramSocketClient creates for network communications. This is especially useful for adding things like proxy support as well as better support for applets. For example, you could create a DatagramSocketFactory that requests browser security capabilities before creating a socket. All classes derived from DatagramSocketClient should use the _socketFactory_ 55 member variable to create DatagramSocket instances rather than instantiating them by directly invoking a constructor. By honoring this contract you guarantee that a user will always be able to provide his own Socket implementations by substituting his own SocketFactory.
| Field Summary | |
private static DatagramSocketFactory |
__DEFAULT_SOCKET_FACTORY
The default DatagramSocketFactory shared by all DatagramSocketClient instances. |
protected boolean |
_isOpen_
A status variable indicating if the client's socket is currently open. |
protected java.net.DatagramSocket |
_socket_
The datagram socket used for the connection. |
protected DatagramSocketFactory |
_socketFactory_
The datagram socket's DatagramSocketFactory. |
protected int |
_timeout_
The timeout to use after opening a socket. |
| Constructor Summary | |
DatagramSocketClient()
Default constructor for DatagramSocketClient. |
|
| Method Summary | |
void |
close()
Closes the DatagramSocket used for the connection. |
int |
getDefaultTimeout()
Returns the default timeout in milliseconds that is used when opening a socket. |
java.net.InetAddress |
getLocalAddress()
Returns the local address to which the client's socket is bound. |
int |
getLocalPort()
Returns the port number of the open socket on the local host used for the connection. |
int |
getSoTimeout()
Returns the timeout in milliseconds of the currently opened socket. |
boolean |
isOpen()
Returns true if the client has a currently open socket. |
void |
open()
Opens a DatagramSocket on the local host at the first available port. |
void |
open(int port)
Opens a DatagramSocket on the local host at a specified port. |
void |
open(int port,
java.net.InetAddress laddr)
Opens a DatagramSocket at the specified address on the local host at a specified port. |
void |
setDatagramSocketFactory(DatagramSocketFactory factory)
Sets the DatagramSocketFactory used by the DatagramSocketClient to open DatagramSockets. |
void |
setDefaultTimeout(int timeout)
Set the default timeout in milliseconds to use when opening a socket. |
void |
setSoTimeout(int timeout)
Set the timeout in milliseconds of a currently open connection. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
__DEFAULT_SOCKET_FACTORY
private static final DatagramSocketFactory __DEFAULT_SOCKET_FACTORY
- The default DatagramSocketFactory shared by all DatagramSocketClient
instances.
_timeout_
protected int _timeout_
- The timeout to use after opening a socket.
_socket_
protected java.net.DatagramSocket _socket_
- The datagram socket used for the connection.
_isOpen_
protected boolean _isOpen_
- A status variable indicating if the client's socket is currently open.
_socketFactory_
protected DatagramSocketFactory _socketFactory_
- The datagram socket's DatagramSocketFactory.
| Constructor Detail |
DatagramSocketClient
public DatagramSocketClient()
- Default constructor for DatagramSocketClient. Initializes
_socket_ to null, _timeout_ to 0, and _isOpen_ to false.
| Method Detail |
open
public void open()
throws java.net.SocketException
- Opens a DatagramSocket on the local host at the first available port.
Also sets the timeout on the socket to the default timeout set
by setDefaultTimeout() 55 .
_isOpen_ is set to true after calling this method and _socket_ is set to the newly opened socket.
open
public void open(int port)
throws java.net.SocketException
- Opens a DatagramSocket on the local host at a specified port.
Also sets the timeout on the socket to the default timeout set
by setDefaultTimeout() 55 .
_isOpen_ is set to true after calling this method and _socket_ is set to the newly opened socket.
open
public void open(int port,
java.net.InetAddress laddr)
throws java.net.SocketException
- Opens a DatagramSocket at the specified address on the local host
at a specified port.
Also sets the timeout on the socket to the default timeout set
by setDefaultTimeout() 55 .
_isOpen_ is set to true after calling this method and _socket_ is set to the newly opened socket.
close
public void close()
- Closes the DatagramSocket used for the connection.
You should call this method after you've finished using the class
instance and also before you call open() 55
again. _isOpen_ is set to false and _socket_ is set to null.
If you call this method when the client socket is not open,
a NullPointerException is thrown.
isOpen
public boolean isOpen()
- Returns true if the client has a currently open socket.
setDefaultTimeout
public void setDefaultTimeout(int timeout)
- Set the default timeout in milliseconds to use when opening a socket.
After a call to open, the timeout for the socket is set using this value.
This method should be used prior to a call to open() 55
and should not be confused with setSoTimeout() 55
which operates on the currently open socket. _timeout_ contains
the new timeout value.
getDefaultTimeout
public int getDefaultTimeout()
- Returns the default timeout in milliseconds that is used when
opening a socket.
setSoTimeout
public void setSoTimeout(int timeout)
throws java.net.SocketException
- Set the timeout in milliseconds of a currently open connection.
Only call this method after a connection has been opened
by open() 55 .
getSoTimeout
public int getSoTimeout()
throws java.net.SocketException
- Returns the timeout in milliseconds of the currently opened socket.
If you call this method when the client socket is not open,
a NullPointerException is thrown.
getLocalPort
public int getLocalPort()
- Returns the port number of the open socket on the local host used
for the connection. If you call this method when the client socket
is not open, a NullPointerException is thrown.
getLocalAddress
public java.net.InetAddress getLocalAddress()
- Returns the local address to which the client's socket is bound.
If you call this method when the client socket is not open, a
NullPointerException is thrown.
setDatagramSocketFactory
public void setDatagramSocketFactory(DatagramSocketFactory factory)
- Sets the DatagramSocketFactory used by the DatagramSocketClient
to open DatagramSockets. If the factory value is null, then a default
factory is used (only do this to reset the factory after having
previously altered it).
|
|||||||||
| Home >> All >> org >> apache >> commons >> [ net overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.commons.net.DatagramSocketClient