| java.lang.Object java.net.DatagramSocket
All known Subclasses: java.net.MulticastSocket,
DatagramSocket | public class DatagramSocket (Code) | | This class models a socket for sending & receiving datagram packets.
See Also: DatagramPacket |
Constructor Summary | |
public | DatagramSocket() Constructs a datagram socket, bound to any available port on the
localhost. | public | DatagramSocket(int aPort) Answers a datagram socket, bound to the nominated port on the localhost. | public | DatagramSocket(int aPort, InetAddress addr) Constructs a datagram socket, bound to the nominated localhost/port. | protected | DatagramSocket(DatagramSocketImpl socketImpl) Constructs a DatagramSocket using the specified DatagramSocketImpl. | public | DatagramSocket(SocketAddress localAddr) Constructs a DatagramSocket bound to the host/port specified by the
SocketAddress, or an unbound DatagramSocket if the SocketAddress is null. |
Method Summary | |
public void | bind(SocketAddress localAddr) Bind the DatagramSocket to the nominated local host/port. | void | checkClosedAndBind(boolean bind) | void | checkListen(int aPort) Sent prior to attempting to bind the socket, check that the port is
within the valid port range and verify with the security manager that the
port may be bound by the current context. | public void | close() Close the socket. | public void | connect(InetAddress anAddress, int aPort) Connect the datagram socket to a remote host and port. | public void | connect(SocketAddress remoteAddr) Connect the datagram socket to a remote host and port. | synchronized void | createSocket(int aPort, InetAddress addr) | public void | disconnect() 'Disconnect' the datagram socket from a remote host and port. | public boolean | getBroadcast() Get the state of the SO_BROADCAST socket option. | public DatagramChannel | getChannel() | public InetAddress | getInetAddress() Returns an
InetAddress instance representing the address this
socket has connected to.
if this socket is connected, the address it is connected to. | public InetAddress | getLocalAddress() Returns an
InetAddress instance representing the local
address this socket is bound to. | public int | getLocalPort() Answer the local port to which the socket is bound. | public SocketAddress | getLocalSocketAddress() Answer the local SocketAddress for this socket, or null if the socket is
not bound. | public int | getPort() Returns the number of the remote port this socket is connected to.
int the remote port number that this socket has connected to. | public synchronized int | getReceiveBufferSize() Answer the socket receive buffer size (SO_RCVBUF). | public SocketAddress | getRemoteSocketAddress() Answer the remote SocketAddress for this socket, or null if the socket is
not connected. | public boolean | getReuseAddress() Get the state of the SO_REUSEADDR socket option. | public synchronized int | getSendBufferSize() Answer the socket send buffer size (SO_SNDBUF). | public synchronized int | getSoTimeout() Answer the socket receive timeout (SO_RCVTIMEOUT), in milliseconds. | public int | getTrafficClass() Get the IP_TOS socket option. | public boolean | isBound() Return if the socket is bound to a local address and port. | public boolean | isClosed() Return if the socket is closed. | public boolean | isConnected() Return if the socket is connected. | public synchronized void | receive(DatagramPacket pack) Receive on this socket into the packet argument. | public void | send(DatagramPacket pack) Send the packet on this socket. | public void | setBroadcast(boolean broadcast) Set the SO_BROADCAST socket option. | public static synchronized void | setDatagramSocketImplFactory(DatagramSocketImplFactory fac) Specifies the application's socket implementation factory. | public synchronized void | setReceiveBufferSize(int size) Set the socket receive buffer size.
Parameters: size - the buffer size, in bytes. | public void | setReuseAddress(boolean reuse) Set the SO_REUSEADDR socket option. | public synchronized void | setSendBufferSize(int size) Set the socket send buffer size.
Parameters: size - the buffer size, in bytes. | public synchronized void | setSoTimeout(int timeout) Set the SO_RCVTIMEOUT to timeout , in milliseconds. | public void | setTrafficClass(int value) Set the IP_TOS socket option. |
DatagramSocket | public DatagramSocket() throws SocketException(Code) | | Constructs a datagram socket, bound to any available port on the
localhost.
throws: SocketException - if a problem occurs creating or binding the socket |
DatagramSocket | public DatagramSocket(int aPort) throws SocketException(Code) | | Answers a datagram socket, bound to the nominated port on the localhost.
Parameters: aPort - the port to bind on the localhost throws: SocketException - if a problem occurs creating or binding the socket |
DatagramSocket | public DatagramSocket(int aPort, InetAddress addr) throws SocketException(Code) | | Constructs a datagram socket, bound to the nominated localhost/port.
Parameters: aPort - the port on the localhost to bind Parameters: addr - the address on the multihomed localhost to bind throws: SocketException - if a problem occurs creating or binding the socket |
DatagramSocket | protected DatagramSocket(DatagramSocketImpl socketImpl)(Code) | | Constructs a DatagramSocket using the specified DatagramSocketImpl. The
DatagramSocket is not bound.
Parameters: socketImpl - the DatagramSocketImpl to use |
DatagramSocket | public DatagramSocket(SocketAddress localAddr) throws SocketException(Code) | | Constructs a DatagramSocket bound to the host/port specified by the
SocketAddress, or an unbound DatagramSocket if the SocketAddress is null.
Parameters: localAddr - the local machine address and port to bind to throws: IllegalArgumentException - if the SocketAddress is not supported throws: SocketException - if a problem occurs creating or binding the socket |
bind | public void bind(SocketAddress localAddr) throws SocketException(Code) | | Bind the DatagramSocket to the nominated local host/port.
Parameters: localAddr - the local machine address and port to bind on throws: IllegalArgumentException - if the SocketAddress is not supported throws: SocketException - if the socket is already bound, or a problem occurs duringthe bind |
checkListen | void checkListen(int aPort)(Code) | | Sent prior to attempting to bind the socket, check that the port is
within the valid port range and verify with the security manager that the
port may be bound by the current context.
Parameters: aPort - the port on the localhost that is to be bound |
close | public void close()(Code) | | Close the socket.
|
connect | public void connect(InetAddress anAddress, int aPort)(Code) | | Connect the datagram socket to a remote host and port. The host and port
are validated, thereafter the only validation on send() and receive() is
that the packet address/port matches the connected target.
Parameters: anAddress - the target address Parameters: aPort - the target port |
connect | public void connect(SocketAddress remoteAddr) throws SocketException(Code) | | Connect the datagram socket to a remote host and port. The host and port
are validated, thereafter the only validation on send() and receive() is
that the packet address/port matches the connected target.
Parameters: remoteAddr - the target address and port exception: SocketException - if a problem occurs during the connect |
disconnect | public void disconnect()(Code) | | 'Disconnect' the datagram socket from a remote host and port. This method
may be called on an unconnected socket.
|
getBroadcast | public boolean getBroadcast() throws SocketException(Code) | | Get the state of the SO_BROADCAST socket option.
true if the SO_BROADCAST is enabled,false otherwise. throws: SocketException - if the socket is closed or the option is invalid. |
getChannel | public DatagramChannel getChannel()(Code) | | if DatagramSocket is created by a DatagramChannel, returns the related
DatagramChannel
the related DatagramChannel if any |
getInetAddress | public InetAddress getInetAddress()(Code) | | Returns an
InetAddress instance representing the address this
socket has connected to.
if this socket is connected, the address it is connected to. Anull return signifies no connection has been made. |
getLocalAddress | public InetAddress getLocalAddress()(Code) | | Returns an
InetAddress instance representing the local
address this socket is bound to.
the local address to which the socket is bound |
getLocalPort | public int getLocalPort()(Code) | | Answer the local port to which the socket is bound.
int local port to which the socket is bound |
getLocalSocketAddress | public SocketAddress getLocalSocketAddress()(Code) | | Answer the local SocketAddress for this socket, or null if the socket is
not bound.
This is useful on multihomed hosts.
the local socket address |
getPort | public int getPort()(Code) | | Returns the number of the remote port this socket is connected to.
int the remote port number that this socket has connected to. Areturn of -1 indicates that there is no connectionin place. |
getReceiveBufferSize | public synchronized int getReceiveBufferSize() throws SocketException(Code) | | Answer the socket receive buffer size (SO_RCVBUF).
int socket receive buffer size exception: SocketException - when an error occurs |
getRemoteSocketAddress | public SocketAddress getRemoteSocketAddress()(Code) | | Answer the remote SocketAddress for this socket, or null if the socket is
not connected.
the remote socket address |
getReuseAddress | public boolean getReuseAddress() throws SocketException(Code) | | Get the state of the SO_REUSEADDR socket option.
true if the SO_REUSEADDR is enabled,false otherwise. throws: SocketException - if the socket is closed or the option is invalid. |
getSendBufferSize | public synchronized int getSendBufferSize() throws SocketException(Code) | | Answer the socket send buffer size (SO_SNDBUF).
int socket send buffer size exception: SocketException - when an error occurs |
getSoTimeout | public synchronized int getSoTimeout() throws SocketException(Code) | | Answer the socket receive timeout (SO_RCVTIMEOUT), in milliseconds. Zero
implies the timeout is disabled.
int socket receive timeout exception: SocketException - when an error occurs |
getTrafficClass | public int getTrafficClass() throws SocketException(Code) | | Get the IP_TOS socket option.
the IP_TOS socket option value throws: SocketException - if the option is invalid |
isBound | public boolean isBound()(Code) | | Return if the socket is bound to a local address and port.
true if the socket is bound to a local address,false otherwise. |
isClosed | public boolean isClosed()(Code) | | Return if the socket is closed.
true if the socket is closed, false otherwise. |
isConnected | public boolean isConnected()(Code) | | Return if the socket is connected.
true if the socket is connected,false otherwise. |
receive | public synchronized void receive(DatagramPacket pack) throws IOException(Code) | | Receive on this socket into the packet argument. This method blocks until
a packet is received or, if a timeout has been defined, the timeout
period expires. If this is a connected socket, the packet host/port are
compared to the connection host/port otherwise the security manager if
present is queried whether the packet host/port is acceptable. Any
packets from unacceptable origins will be silently discarded. The packet
fields are set according to the data received. If the received data is
longer than the packet buffer, it is truncated.
Parameters: pack - the DatagramPacket to receive data into exception: java.io.IOException - If a receive error occurs. |
send | public void send(DatagramPacket pack) throws IOException(Code) | | Send the packet on this socket. The packet must satisfy the security
policy before it may be sent.
Parameters: pack - the DatagramPacket to send exception: java.io.IOException - If a send error occurs. |
setBroadcast | public void setBroadcast(boolean broadcast) throws SocketException(Code) | | Set the SO_BROADCAST socket option.
Parameters: broadcast - the socket SO_BROADCAST option setting throws: SocketException - if the socket is closed or the option is invalid. |
setDatagramSocketImplFactory | public static synchronized void setDatagramSocketImplFactory(DatagramSocketImplFactory fac) throws IOException(Code) | | Specifies the application's socket implementation factory. This may only
be invoked once over the lifetime of the application.
Parameters: fac - the socket factory to set exception: IOException - thrown if the factory has already been set |
setReceiveBufferSize | public synchronized void setReceiveBufferSize(int size) throws SocketException(Code) | | Set the socket receive buffer size.
Parameters: size - the buffer size, in bytes. Must be at least one byte. exception: java.net.SocketException - If an error occurs while setting the size or the size isinvalid. |
setReuseAddress | public void setReuseAddress(boolean reuse) throws SocketException(Code) | | Set the SO_REUSEADDR socket option.
Parameters: reuse - the socket SO_REUSEADDR option setting throws: SocketException - if the socket is closed or the option is invalid. |
setSendBufferSize | public synchronized void setSendBufferSize(int size) throws SocketException(Code) | | Set the socket send buffer size.
Parameters: size - the buffer size, in bytes. Must be at least one byte. exception: java.net.SocketException - If an error occurs while setting the size or the size isinvalid. |
setSoTimeout | public synchronized void setSoTimeout(int timeout) throws SocketException(Code) | | Set the SO_RCVTIMEOUT to timeout , in milliseconds. The
receive timeout defines the period a socket will block waiting to receive
data, before throwing an InterruptedIOException.
Parameters: timeout - the timeout period, in milliseconds exception: java.net.SocketException - If an error occurs while setting the timeout or the periodis invalid. |
setTrafficClass | public void setTrafficClass(int value) throws SocketException(Code) | | Set the IP_TOS socket option.
Parameters: value - the socket IP_TOS setting throws: SocketException - if the socket is closed or the option is invalid. |
|
|