public class DatagramSocket
extends java.lang.Object
Constructor and Description |
---|
DatagramSocket()
Create a DatagramSocket bound to a a free port.
|
DatagramSocket(Address addr,
int port)
Create a DatagramSocket connected to a specified remote Address and port.
|
DatagramSocket(int port)
Create a DatagramSocket bound to a port.
|
Modifier and Type | Method and Description |
---|---|
void |
bind(int port)
Binds this DatagramSocket to a port.
|
void |
close()
Close this socket.
|
void |
connect(Address address,
int port)
Connects the socket to a remote address for this socket.
|
void |
connect(SocketAddress sockaddr)
Connects the socket to a remote address for this socket.
|
void |
disconnect()
Disconnects the socket.
|
Address |
getLocalAddress()
Returns the address of the endpoint this socket is bound to,
or null if it is not bound yet.
|
int |
getLocalPort()
Returns the local port for this socket
to which this socket is bound.
|
int |
getPort()
Returns the remote port for this socket.
|
Address |
getRemoteAddress()
Returns the address to which this socket is connected.
|
int |
getSoTimeout()
Retrive setting for SO_TIMEOUT.
|
boolean |
isBound()
Returns the bound state of the socket.
|
boolean |
isClosed()
Returns the bound state of the socket.
|
boolean |
isConnected()
Returns the connection state of the socket.
|
Datagram |
receive()
Receives a datagram from this socket.
|
void |
send(Datagram dg)
Send a datagram from this socket.
|
void |
setSoTimeout(int timeout)
Enable/disable SO_TIMEOUT with the specified timeout, in
milliseconds.
|
java.lang.String |
toString()
toString.
|
public DatagramSocket() throws java.net.SocketException
java.net.SocketException
public DatagramSocket(int port) throws java.net.SocketException
java.net.SocketException
public DatagramSocket(Address addr, int port) throws java.net.SocketException
java.net.SocketException
public void bind(int port) throws java.net.SocketException
java.net.SocketException
public void connect(SocketAddress sockaddr)
public void connect(Address address, int port)
public int getPort()
public Address getRemoteAddress()
public boolean isConnected()
public boolean isBound()
public boolean isClosed()
public int getLocalPort()
public Address getLocalAddress()
public void send(Datagram dg) throws java.net.SocketException, java.net.NoRouteToHostException
java.net.SocketException
java.net.NoRouteToHostException
public Datagram receive() throws java.net.SocketException, SocketTimeoutException
java.net.SocketException
SocketTimeoutException
public void close()
public void disconnect()
public int getSoTimeout() throws java.net.SocketException
java.net.SocketException
public void setSoTimeout(int timeout) throws java.net.SocketException
java.net.SocketException
public java.lang.String toString()
toString
in class java.lang.Object
User Space Routing 0.10.3