MulticastSocket Class Reference

A UDP multicast socket. More...

#include <MulticastSocket.h++>

Inheritance diagram for MulticastSocket:

Inheritance graph
[legend]
Collaboration diagram for MulticastSocket:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 MulticastSocket (uint16_t port=0) throw ()
 Construct a new MulticastSocket bound to the given port.
 ~MulticastSocket () throw ()
 Destructor.
void join (const String &address) throw (SocketException)
 Join a multicast group.
void join (const InetAddress &address) throw (SocketException)
 Join a multicast group.
void join (const String &address, const NetworkInterface &ixface) throw (SocketException)
 Join a multicast group on a specific interface.
void join (const InetAddress &address, const NetworkInterface &ixface) throw (SocketException)
 Join a multicast group on a specific interface.
void leave (const String &address) throw (SocketException)
 Leave a multicast group.
void leave (const InetAddress &address) throw (SocketException)
 Leave a multicast group.
void leave (const String &address, const ccxx::NetworkInterface &ixface) throw (SocketException)
 Leave a multicast group on a specific interface.
void leave (const InetAddress &address, const ccxx::NetworkInterface &ixface) throw (SocketException)
 Leave a multicast group on a specific interface.
void setTTL (uint8_t ttl) throw (SocketException)
 Set the TTL (time-to-live) value for outgoing multicast datagrams.
uint8_t getTTL () const throw (SocketException)
 Get the TTL value.
void setLoopbackEnabled (bool enabled) throw (SocketException)
 Enable or disable local loopback of multicast datagrams.
bool isLoopbackEnabled () const throw (SocketException)
 Determine if local loopback is enabled.
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 (int msec) 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 (int msec) throw (SocketException)
 Set the linger time for the socket.
int 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 SocketAddressgetLocalAddress () const throw ()
 Get the address of the local end of the socket.
const SocketAddressgetRemoteAddress () const throw ()
 Get the address of the remote (peer) end of the socket.

Static Public Attributes

static uint8_t TTL_HOST = 0
 A TTL value representing localhost scope.
static uint8_t TTL_SUBNET = 1
 A TTL value representing subnet scope.
static uint8_t TTL_SITE = 32
 A TTL value representing site-wide scope.
static uint8_t TTL_REGION = 64
 A TTL value representing regional scope.
static uint8_t TTL_CONTINENT = 128
 A TTL value representing continental scope.
static uint8_t TTL_UNRESTRICTED = 255
 A TTL value representing unlimited scope.
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.
bool _connected
bool _reuseAddr


Detailed Description

A UDP multicast socket.

Multicast socket addresses range from 224.0.0.0 to 239.255.255.255, inclusive, with 224.0.0.0 reserved.

Author:
Mark Lindner

Member Enumeration Documentation

enum IOWaitMode [protected, inherited]

Enumerator:
WaitWrite 
WaitRead 


Constructor & Destructor Documentation

MulticastSocket ( uint16_t  port = 0  )  throw ()

Construct a new MulticastSocket bound to the given port.

Parameters:
port The port on which to listen.

~MulticastSocket (  )  throw ()

Destructor.


Member Function Documentation

void connect ( const SocketAddress addr  )  throw (IOException) [virtual, inherited]

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.

Parameters:
addr The address.
Exceptions:
IOException If an error occurs.

Reimplemented from Socket.

void connect ( const String addr,
uint16_t  port 
) throw (IOException) [virtual, inherited]

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.

Parameters:
addr The address, which may either be a dot-separated IP address or a DNS name.
port The port number.
Exceptions:
IOException If an error occurs.

Reimplemented from Socket.

bool getBroadcast (  )  const throw (SocketException) [inherited]

Determine if broadcast is enabled.

Returns:
true if broadcast is enabled, false otherwise.
Exceptions:
SocketException If an error occurs.

bool getKeepAlive (  )  throw (SocketException) [inherited]

Determine if the SO_KEEPALIVE option is enabled or disabled.

Returns:
true if the option is enabled, false otherwise.
Exceptions:
SocketException If a socket error occurs.

int getLingerTime (  )  const throw (SocketException) [inherited]

Get the linger time for the socket.

Returns:
The linger time, in milliseconds, or -1 if the feature is disabled.
Exceptions:
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.

Returns:
The size, in bytes.
Exceptions:
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.

Returns:
true if the option is enabled, false otherwise.
Exceptions:
SocketException If a socket error occurs.

size_t getSendBufSize (  )  const throw (SocketException) [inherited]

Get the size of the socket's internal send buffer.

Returns:
The size, in bytes.
Exceptions:
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.

Returns:
true if the Nagle algorithm is enabled (TCP_NODELAY off), false otherwise.
Exceptions:
SocketException If a socket error occurs.

uint8_t getTTL (  )  const throw (SocketException)

Get the TTL value.

Exceptions:
SocketException If the operation fails.

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.

Exceptions:
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.

bool isLoopbackEnabled (  )  const throw (SocketException)

Determine if local loopback is enabled.

Returns:
true if loopback is enabled, false otherwise.
Exceptions:
SocketException If the operation fails.

void join ( const InetAddress address,
const NetworkInterface ixface 
) throw (SocketException)

Join a multicast group on a specific interface.

Parameters:
address The address to join.
ixface The network interface.
Exceptions:
SocketException If the operation fails.

void join ( const String address,
const NetworkInterface ixface 
) throw (SocketException)

Join a multicast group on a specific interface.

Parameters:
address The address to join, as a dot-separated IP address.
ixface The network interface.
Exceptions:
SocketException If the operation fails.

void join ( const InetAddress address  )  throw (SocketException)

Join a multicast group.

Parameters:
address The address to join.
Exceptions:
SocketException If the operation fails.

void join ( const String address  )  throw (SocketException)

Join a multicast group.

Parameters:
address The address to join, as a dot-separated IP address.
Exceptions:
SocketException If the operation fails.

void leave ( const InetAddress address,
const ccxx::NetworkInterface ixface 
) throw (SocketException)

Leave a multicast group on a specific interface.

Parameters:
address The address to leave.
ixface The network interface.
Exceptions:
SocketException If the operation fails.

void leave ( const String address,
const ccxx::NetworkInterface ixface 
) throw (SocketException)

Leave a multicast group on a specific interface.

Parameters:
address The address to leave, as a dot-separated IP address.
ixface The network interface.
Exceptions:
SocketException If the operation fails.

void leave ( const InetAddress address  )  throw (SocketException)

Leave a multicast group.

Parameters:
address The address to leave.
Exceptions:
SocketException If the operation fails.

void leave ( const String address  )  throw (SocketException)

Leave a multicast group.

Parameters:
address The address to leave, as a dot-separated IP address.
Exceptions:
SocketException If the operation fails.

size_t receive ( ByteBuffer buffer,
SocketAddress source 
) throw (IOException) [inherited]

Receive a datagram and write it to a buffer.

Parameters:
buffer The buffer to write the data to.
source The object in which to place the source address of the received datagram.
Returns:
The number of bytes received.
Exceptions:
IOException If an error occurs.

size_t receive ( byte_t buffer,
size_t  buflen,
SocketAddress source 
) throw (IOException) [inherited]

Receive a datagram and write it to a buffer.

Parameters:
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.
Returns:
The number of bytes received.
Exceptions:
IOException If an error occurs.

size_t receive ( ByteBuffer buffer  )  throw (IOException) [inherited]

Receive a datagram from the remote endpoint, and write it to a buffer.

The socket must be connected before this method can be used.

Parameters:
buffer The buffer to write the data to.
Returns:
The number of bytes received.
Exceptions:
IOException If an error occurs.

size_t receive ( byte_t buffer,
size_t  buflen 
) throw (IOException) [inherited]

Receive a datagram from the remote endpoint, and write it to a buffer.

The socket must be connected before this method can be used.

Parameters:
buffer The raw buffer to write the data to.
buflen The length of the buffer.
Returns:
The number of bytes received.
Exceptions:
IOException If an error occurs.

size_t send ( ByteBuffer buffer,
const SocketAddress dest 
) throw (IOException) [inherited]

Send a datagram to a given address.

Parameters:
buffer The buffer containing the data to send.
dest The destination address.
Returns:
The number of bytes sent.
Exceptions:
IOException If an error occurs.

size_t send ( const byte_t buffer,
size_t  buflen,
const SocketAddress dest 
) throw (IOException) [inherited]

Send a datagram to a given address.

Parameters:
buffer The raw buffer containing the data to send.
buflen The length of the buffer.
dest The destination address.
Returns:
The number of bytes sent.
Exceptions:
IOException If an error occurs.

size_t send ( ByteBuffer buffer  )  throw (IOException) [inherited]

Send a datagram to the remote endpoint.

The socket must be connected before this method can be used.

Parameters:
buffer The buffer containing the data to send.
Returns:
The number of bytes sent.
Exceptions:
IOException If an error occurs.

size_t send ( const byte_t buffer,
size_t  buflen 
) throw (IOException) [inherited]

Send a datagram to the remote endpoint.

The socket must be connected before this method can be used.

Parameters:
buffer The raw buffer containing the data to send.
buflen The length of the buffer.
Returns:
The number of bytes sent.
Exceptions:
IOException If an error occurs.

void setBroadcast ( bool  flag  )  throw (SocketException) [inherited]

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.

Parameters:
flag A flag indicating whether the feature should be enabled or disabled.
Exceptions:
SocketException If an error occurs.

void setKeepAlive ( bool  enable  )  throw (SocketException) [inherited]

Enable or disable the SO_KEEPALIVE option on the socket.

Parameters:
enable true to enable the option false to disable it.
Exceptions:
SocketException If a socket error occurs.

void setLingerTime ( int  msec  )  throw (SocketException) [inherited]

Set the linger time for the socket.

Parameters:
msec The new linger time, in milliseconds; a negative value disables the linger feature.
Exceptions:
SocketException If the linger time could not be changed.

void setLoopbackEnabled ( bool  enabled  )  throw (SocketException)

Enable or disable local loopback of multicast datagrams.

When the loopback is enabled, the sender receives copies of all multicast datagrams that it sends.

Parameters:
enabled true if loopback should be enabled, false if it should be disabled.
Exceptions:
SocketException If the operation fails.

void setReceiveBufSize ( size_t  size  )  throw (SocketException) [inherited]

Set the size of the socket's internal receive buffer.

Parameters:
size The new size, in bytes.
Exceptions:
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.

Parameters:
enable true to enable the option false to disable it.
Exceptions:
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.

Parameters:
size The new size, in bytes.
Exceptions:
SocketException If the size could not be changed.

void setTCPDelay ( bool  enable  )  throw (SocketException) [inherited]

Enable or disable the Nagle algorithm for send coalescing.

Parameters:
enable true to enable the Nagle algorithm (TCP_NODELAY off), false to disable it (TCP_NODELAY on).
Exceptions:
SocketException If a socket error occurs.

void setTimeout ( int  msec  )  throw (SocketException) [inherited]

Set the timeout for the socket.

The timeout affects both I/O and connections.

Parameters:
msec The timeout, in milliseconds.
Exceptions:
SocketException If an error occurs.

Reimplemented in StreamSocket.

void setTTL ( uint8_t  ttl  )  throw (SocketException)

Set the TTL (time-to-live) value for outgoing multicast datagrams.

The TTL is the number of "hops" that a packet is allowed to make on the network before being discarded.

Parameters:
ttl The new TTL value.
Exceptions:
SocketException If the operation fails.

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.

Parameters:
mode The wait mode; one of WaitWrite or WaitRead.
Exceptions:
IOException On timeout or other error.


Member Data Documentation

bool _connected [protected, inherited]

SocketAddress _laddr [protected, inherited]

The local address.

SocketAddress _raddr [protected, inherited]

The remote address.

bool _reuseAddr [protected, inherited]

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, inherited]

The maximum size of a datagram packet.

uint8_t TTL_CONTINENT = 128 [static]

A TTL value representing continental scope.

uint8_t TTL_HOST = 0 [static]

A TTL value representing localhost scope.

uint8_t TTL_REGION = 64 [static]

A TTL value representing regional scope.

uint8_t TTL_SITE = 32 [static]

A TTL value representing site-wide scope.

uint8_t TTL_SUBNET = 1 [static]

A TTL value representing subnet scope.

uint8_t TTL_UNRESTRICTED = 255 [static]

A TTL value representing unlimited scope.


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

Generated on Sat Apr 17 23:03:09 2010 for libcommonc++ by  doxygen 1.5.9