DthingApi
Public Member Functions | Protected Member Functions | List of all members
java.net.DatagramSocket Class Reference

Public Member Functions

 DatagramSocket () throws SocketException
 
 DatagramSocket (int aPort) throws SocketException
 
 DatagramSocket (int aPort, InetAddress addr) throws SocketException
 
void close ()
 
void disconnect ()
 
InetAddress getInetAddress ()
 
InetAddress getLocalAddress ()
 
int getLocalPort ()
 
int getPort ()
 
synchronized int getReceiveBufferSize () throws SocketException
 
synchronized int getSendBufferSize () throws SocketException
 
synchronized int getSoTimeout () throws SocketException
 
synchronized void receive (DatagramPacket pack) throws IOException
 
void send (DatagramPacket pack) throws IOException
 
synchronized void setSendBufferSize (int size) throws SocketException
 
synchronized void setReceiveBufferSize (int size) throws SocketException
 
synchronized void setSoTimeout (int timeout) throws SocketException
 
 DatagramSocket (SocketAddress localAddr) throws SocketException
 
void bind (SocketAddress localAddr) throws SocketException
 
void connect (SocketAddress peer) throws SocketException
 
void connect (InetAddress address, int port)
 
boolean isBound ()
 
boolean isConnected ()
 
SocketAddress getRemoteSocketAddress ()
 
SocketAddress getLocalSocketAddress ()
 
boolean getReuseAddress () throws SocketException
 
boolean getBroadcast () throws SocketException
 
void setTrafficClass (int value) throws SocketException
 
int getTrafficClass () throws SocketException
 
boolean isClosed ()
 

Protected Member Functions

 DatagramSocket (DatagramSocketImpl socketImpl)
 

Detailed Description

This class implements a UDP socket for sending and receiving

DatagramPacket

. A

object can be used for both endpoints of a connection for a packet delivery service.

See also
DatagramPacket
DatagramSocketImplFactory

Constructor & Destructor Documentation

◆ DatagramSocket() [1/5]

java.net.DatagramSocket.DatagramSocket ( ) throws SocketException
inline

Constructs a UDP datagram socket which is bound to any available port on the localhost.

Exceptions
SocketExceptionif an error occurs while creating or binding the socket.

◆ DatagramSocket() [2/5]

java.net.DatagramSocket.DatagramSocket ( int  aPort) throws SocketException
inline

Constructs a UDP datagram socket which is bound to the specific port

aPort

on the localhost. Valid values for

aPort

are between 0 and 65535 inclusive.

Parameters
aPortthe port to bind on the localhost.
Exceptions
SocketExceptionif an error occurs while creating or binding the socket.

◆ DatagramSocket() [3/5]

java.net.DatagramSocket.DatagramSocket ( int  aPort,
InetAddress  addr 
) throws SocketException
inline

Constructs a UDP datagram socket which is bound to the specific local address

addr

on port

aPort

. Valid values for

aPort

are between 0 and 65535 inclusive.

Parameters
aPortthe port to bind on the localhost.
addrthe address to bind on the localhost.
Exceptions
SocketExceptionif an error occurs while creating or binding the socket.

◆ DatagramSocket() [4/5]

java.net.DatagramSocket.DatagramSocket ( DatagramSocketImpl  socketImpl)
inlineprotected

Constructs a new

using the specific datagram socket implementation

socketImpl

. The created

will not be bound.

Parameters
socketImplthe DatagramSocketImpl to use.

◆ DatagramSocket() [5/5]

java.net.DatagramSocket.DatagramSocket ( SocketAddress  localAddr) throws SocketException
inline

Constructs a new

bound to the host/port specified by the

SocketAddress
localAddr

or an unbound

if the

SocketAddress

is

null

.

Parameters
localAddrthe local machine address and port to bind to.
Exceptions
IllegalArgumentExceptionif the SocketAddress is not supported
SocketExceptionif a problem occurs creating or binding the socket.

Member Function Documentation

◆ bind()

void java.net.DatagramSocket.bind ( SocketAddress  localAddr) throws SocketException
inline

Binds this socket to the local address and port specified by

localAddr

. If this value is

null

any free port on a valid local address is used.

Parameters
localAddrthe local machine address and port to bind on.
Exceptions
IllegalArgumentExceptionif the SocketAddress is not supported
SocketExceptionif the socket is already bound or a problem occurs during binding.

◆ close()

void java.net.DatagramSocket.close ( )
inline

Closes this UDP datagram socket and all possibly associated channels.

◆ connect() [1/2]

void java.net.DatagramSocket.connect ( SocketAddress  peer) throws SocketException
inline

Connects this datagram socket to the address and port specified by

peer

. Future calls to send will use this as the default target, and receive will only accept packets from this source.

Exceptions
SocketExceptionif an error occurs.

◆ connect() [2/2]

void java.net.DatagramSocket.connect ( InetAddress  address,
int  port 
)
inline

Connects this datagram socket to the specific

address

and

port

. Future calls to send will use this as the default target, and receive will only accept packets from this source.

Beware: because it can't throw, this method silently ignores failures. Use connect(SocketAddress) instead.

◆ disconnect()

void java.net.DatagramSocket.disconnect ( )
inline

Disconnects this UDP datagram socket from the remote host. This method called on an unconnected socket does nothing.

◆ getBroadcast()

boolean java.net.DatagramSocket.getBroadcast ( ) throws SocketException
inline

Gets the state of the socket option

SocketOptions.SO_BROADCAST

.

Returns
true
if the option is enabled,
false
otherwise.
Exceptions
SocketExceptionif the socket is closed or the option is invalid.

◆ getInetAddress()

InetAddress java.net.DatagramSocket.getInetAddress ( )
inline

Gets the

InetAddress

instance representing the remote address to which this UDP datagram socket is connected.

Returns
the remote address this socket is connected to or
null
if this socket is not connected.

◆ getLocalAddress()

InetAddress java.net.DatagramSocket.getLocalAddress ( )
inline

Gets the

InetAddress

instance representing the bound local address of this UDP datagram socket.

Returns
the local address to which this socket is bound to or
null
if this socket is closed.

◆ getLocalPort()

int java.net.DatagramSocket.getLocalPort ( )
inline

Gets the local port which this socket is bound to.

Returns
the local port of this socket or
-1
if this socket is closed and
0
if it is unbound.

◆ getLocalSocketAddress()

SocketAddress java.net.DatagramSocket.getLocalSocketAddress ( )
inline

Returns the

SocketAddress

this socket is bound to, or null for an unbound socket.

◆ getPort()

int java.net.DatagramSocket.getPort ( )
inline

Gets the remote port which this socket is connected to.

Returns
the remote port of this socket. The return value
-1
indicates that this socket is not connected.

◆ getReceiveBufferSize()

synchronized int java.net.DatagramSocket.getReceiveBufferSize ( ) throws SocketException
inline

Returns this socket's receive buffer size.

◆ getRemoteSocketAddress()

SocketAddress java.net.DatagramSocket.getRemoteSocketAddress ( )
inline

Returns the

SocketAddress

this socket is connected to, or null for an unconnected socket.

◆ getReuseAddress()

boolean java.net.DatagramSocket.getReuseAddress ( ) throws SocketException
inline

Gets the state of the socket option

SocketOptions.SO_REUSEADDR

.

Returns
true
if the option is enabled,
false
otherwise.
Exceptions
SocketExceptionif the socket is closed or the option is invalid.

◆ getSendBufferSize()

synchronized int java.net.DatagramSocket.getSendBufferSize ( ) throws SocketException
inline

Returns this socket's send buffer size.

◆ getSoTimeout()

synchronized int java.net.DatagramSocket.getSoTimeout ( ) throws SocketException
inline

Gets the socket receive timeout.

Exceptions
SocketExceptionif an error occurs while getting the option value.

◆ getTrafficClass()

int java.net.DatagramSocket.getTrafficClass ( ) throws SocketException
inline

Returns this socket's {

See also
SocketOptions::IP_TOS} setting.
Exceptions
SocketExceptionif the socket is closed or the option is invalid.

◆ isBound()

boolean java.net.DatagramSocket.isBound ( )
inline

Returns true if this socket is bound to a local address. See bind.

◆ isClosed()

boolean java.net.DatagramSocket.isClosed ( )
inline

Gets the state of this socket.

Returns
true
if the socket is closed,
false
otherwise.

◆ isConnected()

boolean java.net.DatagramSocket.isConnected ( )
inline

Returns true if this datagram socket is connected to a remote address. See connect.

◆ receive()

synchronized void java.net.DatagramSocket.receive ( DatagramPacket  pack) throws IOException
inline

Receives a packet from this socket and stores it in the argument

pack

. All fields of

pack

must be set according to the data received. If the received data is longer than the packet buffer size it is truncated. This method blocks until a packet is received or a timeout has expired.

Parameters
packthe
DatagramPacket
to store the received data.
Exceptions
IOExceptionif an error occurs while receiving the packet.

◆ send()

void java.net.DatagramSocket.send ( DatagramPacket  pack) throws IOException
inline

Sends a packet over this socket.

Parameters
packthe
DatagramPacket
which has to be sent.
Exceptions
IOExceptionif an error occurs while sending the packet.

◆ setReceiveBufferSize()

synchronized void java.net.DatagramSocket.setReceiveBufferSize ( int  size) throws SocketException
inline

Sets this socket's receive buffer size.

◆ setSendBufferSize()

synchronized void java.net.DatagramSocket.setSendBufferSize ( int  size) throws SocketException
inline

Sets this socket's send buffer size.

◆ setSoTimeout()

synchronized void java.net.DatagramSocket.setSoTimeout ( int  timeout) throws SocketException
inline

Sets the read timeout in milliseconds for this socket. This receive timeout defines the period the socket will block waiting to receive data before throwing an

InterruptedIOException

. The value

0

(default) is used to set an infinite timeout. To have effect this option must be set before the blocking method was called.

Parameters
timeoutthe timeout in milliseconds or 0 for no timeout.
Exceptions
SocketExceptionif an error occurs while setting the option.

◆ setTrafficClass()

void java.net.DatagramSocket.setTrafficClass ( int  value) throws SocketException
inline

Sets the {

See also
SocketOptions::IP_TOS} value for every packet sent by this socket.
Exceptions
SocketExceptionif the socket is closed or the option could not be set.

The documentation for this class was generated from the following file: