A User Datagram (UDP) socket. More...
#include <DatagramSocket.h++>

Public Member Functions | |
| DatagramSocket (uint16_t port=0) throw () | |
| Construct a new DatagramSocket. | |
| ~DatagramSocket () throw () | |
| Destructor. | |
| void | connect (const String &addr, uint16_t port) throw (IOException) |
| Connect the datagram socket to a remote endpoint. | |
| void | connect (const SocketAddress &addr) throw (IOException) |
| Connect the datagram socket to a remote endpoint. | |
| size_t | send (const byte_t *buffer, size_t buflen) throw (IOException) |
| Send a datagram to the remote endpoint. | |
| size_t | send (ByteBuffer &buffer) throw (IOException) |
| Send a datagram to the remote endpoint. | |
| size_t | send (const byte_t *buffer, size_t buflen, const SocketAddress &dest) throw (IOException) |
| Send a datagram to a given address. | |
| size_t | send (ByteBuffer &buffer, const SocketAddress &dest) throw (IOException) |
| Send a datagram to a given address. | |
| size_t | receive (byte_t *buffer, size_t buflen) throw (IOException) |
| Receive a datagram from the remote endpoint, and write it to a buffer. | |
| size_t | receive (ByteBuffer &buffer) throw (IOException) |
| Receive a datagram from the remote endpoint, and write it to a buffer. | |
| size_t | receive (byte_t *buffer, size_t buflen, SocketAddress &source) throw (IOException) |
| Receive a datagram and write it to a buffer. | |
| size_t | receive (ByteBuffer &buffer, SocketAddress &source) throw (IOException) |
| Receive a datagram and write it to a buffer. | |
| void | setBroadcast (bool flag) throw (SocketException) |
| Enable or disable broadcast. | |
| bool | getBroadcast () const throw (SocketException) |
| Determine if broadcast is enabled. | |
| virtual void | init () throw (SocketException) |
| Initialize the socket. | |
| virtual void | shutdown () throw () |
| Shut down the socket. | |
| void | setTimeout (timespan_ms_t timeout) throw (SocketException) |
| Set the timeout for the socket. | |
| void | setReceiveBufSize (size_t size) throw (SocketException) |
| Set the size of the socket's internal receive buffer. | |
| size_t | getReceiveBufSize () const throw (SocketException) |
| Get the size of the socket's internal receive buffer. | |
| void | setSendBufSize (size_t size) throw (SocketException) |
| Set the size of the socket's internal send buffer. | |
| size_t | getSendBufSize () const throw (SocketException) |
| Get the size of the socket's internal send buffer. | |
| void | setLingerTime (timespan_s_t timeout) throw (SocketException) |
| Set the linger time for the socket. | |
| timespan_s_t | getLingerTime () const throw (SocketException) |
| Get the linger time for the socket. | |
| void | setReuseAddress (bool enable) throw (SocketException) |
| Enable or disable the SO_REUSEADDR option on the socket. | |
| bool | getReuseAddress () const throw (SocketException) |
| Determine if the SO_REUSEADDR option is enabled or disabled. | |
| void | setKeepAlive (bool enable) throw (SocketException) |
| Enable or disable the SO_KEEPALIVE option on the socket. | |
| bool | getKeepAlive () throw (SocketException) |
| Determine if the SO_KEEPALIVE option is enabled or disabled. | |
| void | setTCPDelay (bool enable) throw (SocketException) |
| Enable or disable the Nagle algorithm for send coalescing. | |
| bool | getTCPDelay () throw (SocketException) |
| Determine if the Nagle algorithm is enabled or disabled. | |
| bool | isInitialized () const throw () |
| Determine if the socket has been initialized. | |
| bool | isConnected () const throw () |
| Determine if the socket is connected. | |
| NetProtocol | getType () const throw () |
| Get the socket type. | |
| const SocketAddress & | getLocalAddress () const throw () |
| Get the address of the local end of the socket. | |
| const SocketAddress & | getRemoteAddress () const throw () |
| Get the address of the remote (peer) end of the socket. | |
Static Public Attributes | |
| static const size_t | MAX_DATAGRAM_SIZE = 16384 |
| The maximum size of a datagram packet. | |
Protected Types | |
| enum | IOWaitMode { WaitWrite, WaitRead } |
Protected Member Functions | |
| SocketHandle | getSocketHandle () const throw () |
| Get the underlying socket handle for this socket. | |
| void | waitForIO (IOWaitMode mode) throw (IOException) |
| Wait for the socket to become ready for reading or writing. | |
Protected Attributes | |
| NetProtocol | _type |
| The socket type. | |
| SocketHandle | _socket |
| A handle to the socket itself. | |
| SocketAddress | _raddr |
| The remote address. | |
| SocketAddress | _laddr |
| The local address. | |
| int | _sotimeout |
| The timeout value. | |
A User Datagram (UDP) socket.
UDP sockets are connectionless and do not provide reliable delivery. Connecting a UDP socket does not establish an actual network connection, but rather specifies the default address to which datagrams are sent and the only address from which datagrams will be received.
enum IOWaitMode [protected, inherited] |
| DatagramSocket | ( | uint16_t | port = 0 |
) | throw () |
Construct a new DatagramSocket.
| port | The local port to bind to, or 0 to bind to an arbitrary port. |
| ~DatagramSocket | ( | ) | throw () |
Destructor.
| void connect | ( | const SocketAddress & | addr | ) | throw (IOException) [virtual] |
Connect the datagram socket to a remote endpoint.
Connecting a datagram socket to an address does not actually establish a network connection, but rather restricts the socket so that it may only exchange datagrams with that address.
| addr | The address. |
| IOException | If an error occurs. |
Reimplemented from Socket.
| void connect | ( | const String & | addr, | |
| uint16_t | port | |||
| ) | throw (IOException) [virtual] |
Connect the datagram socket to a remote endpoint.
Connecting a datagram socket to an address does not actually establish a network connection, but rather restricts the socket so that it may only exchange datagrams with that address.
| addr | The address, which may either be a dot-separated IP address or a DNS name. | |
| port | The port number. |
| IOException | If an error occurs. |
Reimplemented from Socket.
| bool getBroadcast | ( | ) | const throw (SocketException) |
Determine if broadcast is enabled.
| SocketException | If an error occurs. |
| bool getKeepAlive | ( | ) | throw (SocketException) [inherited] |
Determine if the SO_KEEPALIVE option is enabled or disabled.
| SocketException | If a socket error occurs. |
| timespan_s_t getLingerTime | ( | ) | const throw (SocketException) [inherited] |
Get the linger time for the socket.
| SocketException | If the linger time could not be retrieved. |
| const SocketAddress& getLocalAddress | ( | ) | const throw () [inline, inherited] |
Get the address of the local end of the socket.
| size_t getReceiveBufSize | ( | ) | const throw (SocketException) [inherited] |
Get the size of the socket's internal receive buffer.
| SocketException | If the size could not be changed. |
| const SocketAddress& getRemoteAddress | ( | ) | const throw () [inline, inherited] |
Get the address of the remote (peer) end of the socket.
| bool getReuseAddress | ( | ) | const throw (SocketException) [inherited] |
Determine if the SO_REUSEADDR option is enabled or disabled.
| SocketException | If a socket error occurs. |
| size_t getSendBufSize | ( | ) | const throw (SocketException) [inherited] |
Get the size of the socket's internal send buffer.
| SocketException | If the size could not be changed. |
| SocketHandle getSocketHandle | ( | ) | const throw () [inline, protected, inherited] |
Get the underlying socket handle for this socket.
| bool getTCPDelay | ( | ) | throw (SocketException) [inherited] |
Determine if the Nagle algorithm is enabled or disabled.
| SocketException | If a socket error occurs. |
| NetProtocol getType | ( | ) | const throw () [inline, inherited] |
Get the socket type.
| void init | ( | ) | throw (SocketException) [virtual, inherited] |
Initialize the socket.
This method creates the underlying socket object.
| SocketException | If the socket could not be created. |
Reimplemented in ServerSocket.
| bool isConnected | ( | ) | const throw () [inline, inherited] |
Determine if the socket is connected.
| bool isInitialized | ( | ) | const throw () [inline, inherited] |
Determine if the socket has been initialized.
| size_t receive | ( | ByteBuffer & | buffer, | |
| SocketAddress & | source | |||
| ) | throw (IOException) |
Receive a datagram and write it to a buffer.
| buffer | The buffer to write the data to. | |
| source | The object in which to place the source address of the received datagram. |
| IOException | If an error occurs. |
| size_t receive | ( | byte_t * | buffer, | |
| size_t | buflen, | |||
| SocketAddress & | source | |||
| ) | throw (IOException) |
Receive a datagram and write it to a buffer.
| buffer | The raw buffer to write the data to. | |
| buflen | The length of the buffer. | |
| source | The object in which to place the source address of the received datagram. |
| IOException | If an error occurs. |
| size_t receive | ( | ByteBuffer & | buffer | ) | throw (IOException) |
Receive a datagram from the remote endpoint, and write it to a buffer.
The socket must be connected before this method can be used.
| buffer | The buffer to write the data to. |
| IOException | If an error occurs. |
| size_t receive | ( | byte_t * | buffer, | |
| size_t | buflen | |||
| ) | throw (IOException) |
Receive a datagram from the remote endpoint, and write it to a buffer.
The socket must be connected before this method can be used.
| buffer | The raw buffer to write the data to. | |
| buflen | The length of the buffer. |
| IOException | If an error occurs. |
| size_t send | ( | ByteBuffer & | buffer, | |
| const SocketAddress & | dest | |||
| ) | throw (IOException) |
Send a datagram to a given address.
| buffer | The buffer containing the data to send. | |
| dest | The destination address. |
| IOException | If an error occurs. |
| size_t send | ( | const byte_t * | buffer, | |
| size_t | buflen, | |||
| const SocketAddress & | dest | |||
| ) | throw (IOException) |
Send a datagram to a given address.
| buffer | The raw buffer containing the data to send. | |
| buflen | The length of the buffer. | |
| dest | The destination address. |
| IOException | If an error occurs. |
| size_t send | ( | ByteBuffer & | buffer | ) | throw (IOException) |
Send a datagram to the remote endpoint.
The socket must be connected before this method can be used.
| buffer | The buffer containing the data to send. |
| IOException | If an error occurs. |
| size_t send | ( | const byte_t * | buffer, | |
| size_t | buflen | |||
| ) | throw (IOException) |
Send a datagram to the remote endpoint.
The socket must be connected before this method can be used.
| buffer | The raw buffer containing the data to send. | |
| buflen | The length of the buffer. |
| IOException | If an error occurs. |
| void setBroadcast | ( | bool | flag | ) | throw (SocketException) |
Enable or disable broadcast.
When enabled, the socket will receive packets sent to a broadcast address and is allowed to send packets to a broadcast address.
| flag | A flag indicating whether the feature should be enabled or disabled. |
| SocketException | If an error occurs. |
| void setKeepAlive | ( | bool | enable | ) | throw (SocketException) [inherited] |
Enable or disable the SO_KEEPALIVE option on the socket.
| enable | true to enable the option false to disable it. |
| SocketException | If a socket error occurs. |
| void setLingerTime | ( | timespan_s_t | timeout | ) | throw (SocketException) [inherited] |
Set the linger time for the socket.
| timeout | The new linger time, in seconds; a negative value disables the linger feature. |
| SocketException | If the linger time could not be changed. |
| void setReceiveBufSize | ( | size_t | size | ) | throw (SocketException) [inherited] |
Set the size of the socket's internal receive buffer.
| size | The new size, in bytes. |
| SocketException | If the size could not be changed. |
| void setReuseAddress | ( | bool | enable | ) | throw (SocketException) [inherited] |
Enable or disable the SO_REUSEADDR option on the socket.
This method may only be called before the socket has been initialized. This option is off by default in newly created sockets.
| enable | true to enable the option false to disable it. |
| SocketException | If a socket error occurs, or if the call was made after the socket was initialized. |
| void setSendBufSize | ( | size_t | size | ) | throw (SocketException) [inherited] |
Set the size of the socket's internal send buffer.
| size | The new size, in bytes. |
| SocketException | If the size could not be changed. |
| void setTCPDelay | ( | bool | enable | ) | throw (SocketException) [inherited] |
Enable or disable the Nagle algorithm for send coalescing.
| enable | true to enable the Nagle algorithm (TCP_NODELAY off), false to disable it (TCP_NODELAY on). |
| SocketException | If a socket error occurs. |
| void setTimeout | ( | timespan_ms_t | timeout | ) | throw (SocketException) [inherited] |
Set the timeout for the socket.
The timeout affects both I/O and connections.
| timeout | The timeout, in milliseconds. |
| SocketException | If an error occurs. |
Reimplemented in StreamSocket.
| void shutdown | ( | ) | throw () [virtual, inherited] |
Shut down the socket.
Closes the connection and destroys the underlying socket object.
Reimplemented in ServerSocket, and StreamSocket.
| void waitForIO | ( | IOWaitMode | mode | ) | throw (IOException) [protected, inherited] |
Wait for the socket to become ready for reading or writing.
| mode | The wait mode; one of WaitWrite or WaitRead. |
| IOException | On timeout or other error. |
SocketAddress _laddr [protected, inherited] |
The local address.
SocketAddress _raddr [protected, inherited] |
The remote address.
SocketHandle _socket [protected, inherited] |
A handle to the socket itself.
int _sotimeout [protected, inherited] |
The timeout value.
NetProtocol _type [protected, inherited] |
The socket type.
const size_t MAX_DATAGRAM_SIZE = 16384 [static] |
The maximum size of a datagram packet.
1.6.3