|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--java.net.DatagramSocket
This class represents a socket for sending and receiving datagram packets. A datagram socket is the sending or receiving point for a packet delivery service. Each packet sent or received on a datagram socket is individually addressed and routed. Multiple packets sent from one machine to another may be routed differently, and may arrive in any order. UDP broadcasts sends and receives are always enabled on a DatagramSocket.
| Constructor Summary | |
DatagramSocket()
Constructs a datagram socket and binds it to any available port on the local host machine. |
|
DatagramSocket(int port)
Constructs a datagram socket and binds it to the specified port on the local host machine. |
|
DatagramSocket(int port,
InetAddress laddr)
Creates a datagram socket, bound to the specified local address. |
|
| Method Summary | |
void |
close()
Closes this datagram socket. |
void |
connect(InetAddress address,
int port)
|
void |
disconnect()
|
InetAddress |
getInetAddress()
|
InetAddress |
getLocalAddress()
|
int |
getLocalPort()
|
int |
getPort()
|
int |
getSoTimeout()
|
void |
receive(DatagramPacket p)
Receives a datagram packet from this socket. |
void |
send(DatagramPacket p)
Sends a datagram packet from this socket. |
void |
setSoTimeout(int timeout)
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, toString |
| Constructor Detail |
public DatagramSocket()
throws SocketException
SocketException - f the socket could not be opened, or the socket
could not bind to the specified local port.
public DatagramSocket(int port)
throws SocketException
port - local port to use.
SocketException - if the socket could not be opened, or the
socket could not bind to the specified local port.
public DatagramSocket(int port,
InetAddress laddr)
throws SocketException
port - local port to useladdr - local address to bind
SocketException - if the socket could not be opened, or the socket
could not bind to the specified local port.| Method Detail |
public void connect(InetAddress address,
int port)
public void disconnect()
public void close()
public void receive(DatagramPacket p)
throws IOException
p - the DatagramPacket into which to place the incoming data.
IOException - if an I/O error occurs.
public void send(DatagramPacket p)
throws IOException
p - the DatagramPacket to be sent.
IOException - if an I/O error occurs.
public void setSoTimeout(int timeout)
throws SocketException
timeout - the specified timeout in milliseconds.
SocketException - if there is an error in the underlying protocol,
such as a TCP error.
public int getSoTimeout()
throws SocketException
SocketExceptionpublic int getPort()
public int getLocalPort()
public InetAddress getInetAddress()
public InetAddress getLocalAddress()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||