|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectp2ps.imp.net.inet.InetDatagramSocket
A datagram socket implementation that binds to java.net.DatagramSocket
| Constructor Summary | |
InetDatagramSocket(java.net.DatagramSocket socket)
|
|
| Method Summary | |
void |
bind(java.net.SocketAddress addr)
Binds this DatagramSocket to a specific address & port. |
void |
close()
Closes this datagram socket. |
void |
connect(java.net.SocketAddress addr)
Connects this socket to a remote socket address (IP address + port number). |
void |
disconnect()
Disconnects the socket. |
int |
getLocalPort()
Returns the port number on the local host to which this socket is bound. |
java.net.SocketAddress |
getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to, or null if it is not bound yet. |
int |
getPort()
Returns the port for this socket. |
int |
getReceiveBufferSize()
Get value of the SO_RCVBUF option for this DatagramSocket, that is the buffer size used by the platform for input on this DatagramSocket. |
java.net.SocketAddress |
getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, or null if it is unconnected. |
boolean |
getReuseAddress()
Tests if SO_REUSEADDR is enabled. |
int |
getSendBufferSize()
Get value of the SO_SNDBUF option for this DatagramSocket, that is the buffer size used by the platform for output on this DatagramSocket. |
int |
getSoTimeout()
Retrive setting for SO_TIMEOUT. |
boolean |
isBound()
Returns the binding state of the socket. |
boolean |
isClosed()
Returns whether the socket is closed or not. |
boolean |
isConnected()
Returns the connection state of the socket. |
DatagramPacket |
newPacket(byte[] data,
int offset,
int length)
|
DatagramPacket |
newPacket(byte[] data,
int offset,
int length,
java.net.SocketAddress addr)
|
void |
receive(DatagramPacket p)
Receives a datagram packet from this socket. |
void |
send(DatagramPacket p)
Sends a datagram packet from this socket. |
void |
setReceiveBufferSize(int size)
Sets the SO_RCVBUF option to the specified value for this DatagramSocket. |
void |
setReuseAddress(boolean on)
Enable/disable the SO_REUSEADDR socket option. |
void |
setSendBufferSize(int size)
Sets the SO_SNDBUF option to the specified value for this DatagramSocket. |
void |
setSoTimeout(int timeout)
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public InetDatagramSocket(java.net.DatagramSocket socket)
throws java.net.SocketException
| Method Detail |
public DatagramPacket newPacket(byte[] data,
int offset,
int length)
newPacket in interface DatagramSocket
public DatagramPacket newPacket(byte[] data,
int offset,
int length,
java.net.SocketAddress addr)
throws java.net.SocketException
newPacket in interface DatagramSocketjava.net.SocketException
public void bind(java.net.SocketAddress addr)
throws java.net.SocketException
null, then the system will pick up
an ephemeral port and a valid local address to bind the socket.
bind in interface DatagramSocketaddr - The address & port to bind to.
java.lang.IllegalArgumentException - if addr is a SocketAddress subclass
not supported by this socket.
java.net.SocketException - if any error happens during the bind, or if the
socket is already bound.
java.lang.SecurityException - if a security manager exists and its
checkListen method doesn't allow the operation.public boolean isBound()
isBound in interface DatagramSocket
public void connect(java.net.SocketAddress addr)
throws java.net.SocketException
connect in interface DatagramSocketaddr - The remote address.
java.net.SocketException - if the connect fails
java.lang.IllegalArgumentException - if addr is null or addr is a SocketAddress
subclass not supported by this socketconnect(java.net.SocketAddress)public void disconnect()
disconnect in interface DatagramSocketconnect(java.net.SocketAddress)public boolean isConnected()
isConnected in interface DatagramSocketpublic int getLocalPort()
getLocalPort in interface DatagramSocketpublic java.net.SocketAddress getLocalSocketAddress()
null if it is not bound yet.
getLocalSocketAddress in interface DatagramSocketSocketAddress representing the local endpoint of this
socket, or null if it is not bound yet.getLocalPort(),
bind(java.net.SocketAddress)public int getPort()
getPort in interface DatagramSocketpublic java.net.SocketAddress getRemoteSocketAddress()
null if it is unconnected.
getRemoteSocketAddress in interface DatagramSocketSocketAddress representing the remote
endpoint of this socket, or null if it is
not connected yet.getPort(),
connect(java.net.SocketAddress)
public void receive(DatagramPacket p)
throws java.io.IOException
DatagramPacket's buffer is filled with
the data received. The datagram packet also contains the sender's
IP address, and the port number on the sender's machine.
This method blocks until a datagram is received. The
length field of the datagram packet object contains
the length of the received message. If the message is longer than
the packet's length, the message is truncated.
If there is a security manager, a packet cannot be received if the
security manager's checkAccept method
does not allow it.
receive in interface DatagramSocketp - the DatagramPacket into which to place
the incoming data.
java.io.IOException - if an I/O error occurs.
java.net.SocketTimeoutException - if setSoTimeout was previously called
and the timeout has expired.
java.net.PortUnreachableException - may be thrown if the socket is connected
to a currently unreachable destination. Note, there is no guarantee that the
exception will be thrown.
java.nio.channels.IllegalBlockingModeException - if this socket has an associated channel,
and the channel is in non-blocking mode.DatagramPacket,
DatagramSocket
public void send(DatagramPacket p)
throws java.io.IOException
DatagramPacket includes information indicating the
data to be sent, its length, the IP address of the remote host,
and the port number on the remote host.
If there is a security manager, and the socket is not currently
connected to a remote address, this method first performs some
security checks. First, if p.getAddress().isMulticastAddress()
is true, this method calls the
security manager's checkMulticast method
with p.getAddress() as its argument.
If the evaluation of that expression is false,
this method instead calls the security manager's
checkConnect method with arguments
p.getAddress().getHostAddress() and
p.getPort(). Each call to a security manager method
could result in a SecurityException if the operation is not allowed.
send in interface DatagramSocketp - the DatagramPacket to be sent.
java.io.IOException - if an I/O error occurs.
java.lang.SecurityException - if a security manager exists and its
checkMulticast or checkConnect
method doesn't allow the send.
java.net.PortUnreachableException - may be thrown if the socket is connected
to a currently unreachable destination. Note, there is no
guarantee that the exception will be thrown.
java.nio.channels.IllegalBlockingModeException - if this socket has an associated channel,
and the channel is in non-blocking mode.DatagramPacket,
SecurityManager.checkMulticast(java.net.InetAddress),
SecurityManager.checkConnect(java.lang.String, int)public void close()
SocketException.
If this socket has an associated channel then the channel is closed as well.
close in interface DatagramSocketpublic boolean isClosed()
isClosed in interface DatagramSocket
public int getReceiveBufferSize()
throws java.net.SocketException
getReceiveBufferSize in interface DatagramSocketjava.net.SocketException - if there is an error in the underlying protocol, such as an UDP error.setReceiveBufferSize(int)
public void setReceiveBufferSize(int size)
throws java.net.SocketException
getReceiveBufferSize().
Increasing SO_RCVBUF may allow the network implementation
to buffer multiple packets when packets arrive faster than
are being received using receive(DatagramPacket).
Note: It is implementation specific if a packet larger
than SO_RCVBUF can be received.
setReceiveBufferSize in interface DatagramSocketsize - the size to which to set the receive buffer
size. This value must be greater than 0.
java.net.SocketException - if there is an error in
the underlying protocol, such as an UDP error.
java.lang.IllegalArgumentException - if the value is 0 or is
negative.getReceiveBufferSize()
public boolean getReuseAddress()
throws java.net.SocketException
getReuseAddress in interface DatagramSocketboolean indicating whether or not SO_REUSEADDR is enabled.
java.net.SocketException - if there is an error
in the underlying protocol, such as an UDP error.setReuseAddress(boolean)
public void setReuseAddress(boolean on)
throws java.net.SocketException
MulticastSocket). The
SO_REUSEADDR socket option allows multiple
sockets to be bound to the same socket address if the
SO_REUSEADDR socket option is enabled prior
to binding the socket using bind(java.net.SocketAddress).
When a DatagramSocket is created the initial setting
of SO_REUSEADDR is disabled.
The behaviour when SO_REUSEADDR is enabled or
disabled after a socket is bound (See isBound())
is not defined.
setReuseAddress in interface DatagramSocketon - whether to enable or disable the
java.net.SocketException - if an error occurs enabling or
disabling the SO_RESUEADDR socket option,
or the socket is closed.getReuseAddress(),
bind(java.net.SocketAddress),
isBound(),
isClosed()
public int getSendBufferSize()
throws java.net.SocketException
getSendBufferSize in interface DatagramSocketjava.net.SocketException - if there is an error in
the underlying protocol, such as an UDP error.setSendBufferSize(int)
public void setSendBufferSize(int size)
throws java.net.SocketException
getSendBufferSize().
Increasing the buffer size may allow multiple outgoing packets
to be queued by the network implementation when the send rate
is high.
Note: If send(DatagramPacket) is used to send a
DatagramPacket that is larger than the setting
of SO_SNDBUF then it is implementation specific if the
packet is sent or discarded.
setSendBufferSize in interface DatagramSocketsize - the size to which to set the send buffer
size. This value must be greater than 0.
java.net.SocketException - if there is an error
in the underlying protocol, such as an UDP error.
java.lang.IllegalArgumentException - if the value is 0 or is
negative.getSendBufferSize()
public int getSoTimeout()
throws java.net.SocketException
getSoTimeout in interface DatagramSocketjava.net.SocketException - if there is an error in the underlying protocol, such as an UDP error.setSoTimeout(int)
public void setSoTimeout(int timeout)
throws java.net.SocketException
setSoTimeout in interface DatagramSockettimeout - the specified timeout in milliseconds.
java.net.SocketException - if there is an error in the underlying protocol, such as an UDP error.getSoTimeout()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||