|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.net.DatagramSocket
public class DatagramSocket
This class models a socket for sending & receiving datagram packets.
DatagramPacket| Field Summary | |
|---|---|
(package private) InetAddress |
address
|
(package private) static DatagramSocketImplFactory |
factory
|
(package private) DatagramSocketImpl |
impl
|
(package private) boolean |
isBound
|
(package private) int |
port
|
| Constructor Summary | |
|---|---|
|
DatagramSocket()
Constructs a datagram socket, bound to any available port on the localhost. |
protected |
DatagramSocket(DatagramSocketImpl socketImpl)
Constructs a DatagramSocket using the specified DatagramSocketImpl. |
|
DatagramSocket(int aPort)
Returns a datagram socket, bound to the nominated port on the localhost. |
|
DatagramSocket(int aPort,
InetAddress addr)
Constructs a datagram socket, bound to the nominated localhost/port. |
|
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 | |
|---|---|
void |
bind(SocketAddress localAddr)
Bind the DatagramSocket to the nominated local host/port. |
(package private) void |
checkClosedAndBind(boolean bind)
|
(package private) 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. |
void |
close()
Close the socket. |
void |
connect(InetAddress anAddress,
int aPort)
Connect the datagram socket to a remote host and port. |
void |
connect(SocketAddress remoteAddr)
Connect the datagram socket to a remote host and port. |
(package private) void |
createSocket(int aPort,
InetAddress addr)
|
void |
disconnect()
'Disconnect' the datagram socket from a remote host and port. |
boolean |
getBroadcast()
Get the state of the SO_BROADCAST socket option. |
DatagramChannel |
getChannel()
if DatagramSocket is created by a DatagramChannel, returns the related DatagramChannel |
InetAddress |
getInetAddress()
Returns an InetAddress instance representing the address this
socket has connected to. |
InetAddress |
getLocalAddress()
Returns an InetAddress instance representing the local
address this socket is bound to. |
int |
getLocalPort()
Answer the local port to which the socket is bound. |
SocketAddress |
getLocalSocketAddress()
Answer the local SocketAddress for this socket, or null if the socket is not bound. |
int |
getPort()
Returns the number of the remote port this socket is connected to. |
int |
getReceiveBufferSize()
Answer the socket receive buffer size (SO_RCVBUF). |
SocketAddress |
getRemoteSocketAddress()
Answer the remote SocketAddress for this socket, or null if the socket is not connected. |
boolean |
getReuseAddress()
Get the state of the SO_REUSEADDR socket option. |
int |
getSendBufferSize()
Answer the socket send buffer size (SO_SNDBUF). |
int |
getSoTimeout()
Answer the socket receive timeout (SO_RCVTIMEOUT), in milliseconds. |
int |
getTrafficClass()
Get the IP_TOS socket option. |
boolean |
isBound()
Return if the socket is bound to a local address and port. |
boolean |
isClosed()
Return if the socket is closed. |
boolean |
isConnected()
Return if the socket is connected. |
(package private) boolean |
isMulticastSocket()
Returns whether this socket is multicast. |
void |
receive(DatagramPacket pack)
Receive on this socket into the packet argument. |
void |
send(DatagramPacket pack)
Send the packet on this socket. |
void |
setBroadcast(boolean broadcast)
Set the SO_BROADCAST socket option. |
static void |
setDatagramSocketImplFactory(DatagramSocketImplFactory fac)
Specifies the application's socket implementation factory. |
void |
setReceiveBufferSize(int size)
Set the socket receive buffer size. |
void |
setReuseAddress(boolean reuse)
Set the SO_REUSEADDR socket option. |
void |
setSendBufferSize(int size)
Set the socket send buffer size. |
void |
setSoTimeout(int timeout)
Set the SO_RCVTIMEOUT to timeout, in milliseconds. |
void |
setTrafficClass(int value)
Set the IP_TOS socket option. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
DatagramSocketImpl impl
InetAddress address
int port
static DatagramSocketImplFactory factory
boolean isBound
| Constructor Detail |
|---|
public DatagramSocket()
throws SocketException
SocketException - if a problem occurs creating or binding the socket
public DatagramSocket(int aPort)
throws SocketException
aPort - the port to bind on the localhost
SocketException - if a problem occurs creating or binding the socket
public DatagramSocket(int aPort,
InetAddress addr)
throws SocketException
aPort - the port on the localhost to bindaddr - the address on the multihomed localhost to bind
SocketException - if a problem occurs creating or binding the socketprotected DatagramSocket(DatagramSocketImpl socketImpl)
socketImpl - the DatagramSocketImpl to use
public DatagramSocket(SocketAddress localAddr)
throws SocketException
localAddr - the local machine address and port to bind to
IllegalArgumentException - if the SocketAddress is not supported
SocketException - if a problem occurs creating or binding the socket| Method Detail |
|---|
void checkListen(int aPort)
aPort - the port on the localhost that is to be boundpublic void close()
public void connect(InetAddress anAddress,
int aPort)
anAddress - the target addressaPort - the target portpublic void disconnect()
void createSocket(int aPort,
InetAddress addr)
throws SocketException
SocketExceptionpublic InetAddress getInetAddress()
InetAddress instance representing the address this
socket has connected to.
null return signifies no connection has been made.public InetAddress getLocalAddress()
InetAddress instance representing the local
address this socket is bound to.
public int getLocalPort()
public int getPort()
-1 indicates that there is no connection
in place.boolean isMulticastSocket()
public int getReceiveBufferSize()
throws SocketException
SocketException - when an error occurs
public int getSendBufferSize()
throws SocketException
SocketException - when an error occurs
public int getSoTimeout()
throws SocketException
SocketException - when an error occurs
public void receive(DatagramPacket pack)
throws IOException
pack - the DatagramPacket to receive data into
IOException - If a receive error occurs.
public void send(DatagramPacket pack)
throws IOException
pack - the DatagramPacket to send
IOException - If a send error occurs.
public void setSendBufferSize(int size)
throws SocketException
size - the buffer size, in bytes. Must be at least one byte.
SocketException - If an error occurs while setting the size or the size is
invalid.
public void setReceiveBufferSize(int size)
throws SocketException
size - the buffer size, in bytes. Must be at least one byte.
SocketException - If an error occurs while setting the size or the size is
invalid.
public void setSoTimeout(int timeout)
throws SocketException
timeout, in milliseconds. The
receive timeout defines the period a socket will block waiting to receive
data, before throwing an InterruptedIOException.
timeout - the timeout period, in milliseconds
SocketException - If an error occurs while setting the timeout or the period
is invalid.
public static void setDatagramSocketImplFactory(DatagramSocketImplFactory fac)
throws IOException
fac - the socket factory to set
IOException - thrown if the factory has already been set
void checkClosedAndBind(boolean bind)
throws SocketException
SocketException
public void bind(SocketAddress localAddr)
throws SocketException
localAddr - the local machine address and port to bind on
IllegalArgumentException - if the SocketAddress is not supported
SocketException - if the socket is already bound, or a problem occurs during
the bind
public void connect(SocketAddress remoteAddr)
throws SocketException
remoteAddr - the target address and port
SocketException - if a problem occurs during the connectpublic boolean isBound()
true if the socket is bound to a local address,
false otherwise.public boolean isConnected()
true if the socket is connected,
false otherwise.public SocketAddress getRemoteSocketAddress()
public SocketAddress getLocalSocketAddress()
This is useful on multihomed hosts.
public void setReuseAddress(boolean reuse)
throws SocketException
reuse - the socket SO_REUSEADDR option setting
SocketException - if the socket is closed or the option is invalid.
public boolean getReuseAddress()
throws SocketException
true if the SO_REUSEADDR is enabled,
false otherwise.
SocketException - if the socket is closed or the option is invalid.
public void setBroadcast(boolean broadcast)
throws SocketException
broadcast - the socket SO_BROADCAST option setting
SocketException - if the socket is closed or the option is invalid.
public boolean getBroadcast()
throws SocketException
true if the SO_BROADCAST is enabled,
false otherwise.
SocketException - if the socket is closed or the option is invalid.
public void setTrafficClass(int value)
throws SocketException
value - the socket IP_TOS setting
SocketException - if the socket is closed or the option is invalid.
public int getTrafficClass()
throws SocketException
SocketException - if the option is invalidpublic boolean isClosed()
true if the socket is closed, false
otherwise.public DatagramChannel getChannel()
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||