nidas
v1.2-1520
|
A datagram socket to be used for multicasts. More...
#include <Socket.h>
Public Member Functions | |
MulticastSocket () throw (IOException) | |
Create an unbound multicast socket. More... | |
MulticastSocket (int port) throw (IOException) | |
Create multicast socket, bind it to a local port. More... | |
throw (IOException) | |
Creates a datagram socket and binds it to the specified local address. More... | |
void | joinGroup (Inet4Address groupAddr) throw (IOException) |
Join a multicast group on all interfaces. More... | |
void | joinGroup (Inet4Address groupAddr, const Inet4NetworkInterface &iface) throw (IOException) |
Join a multicast group on a given interface. More... | |
void | leaveGroup (Inet4Address groupAddr) throw (IOException) |
Leave a multicast group on all interfaces. More... | |
void | leaveGroup (Inet4Address groupAddr, const Inet4NetworkInterface &iface) throw (IOException) |
Leave a multicast group on a given interface. More... | |
void | setTimeToLive (int val) throw (IOException) |
int | getTimeToLive () const throw (IOException) |
void | setMulticastLoop (bool val) throw (IOException) |
Whether to set the IP_MULTICAST_LOOP socket option. More... | |
bool | getMulticastLoop () const throw (IOException) |
void | setInterface (Inet4Address maddr, const Inet4NetworkInterface &iface) throw (IOException) |
Set the interface for a given multicast address. More... | |
void | setInterface (Inet4Address iaddr) throw (IOException) |
Set the interface for a given multicast address. More... | |
Inet4NetworkInterface | getInterface () const throw (IOException) |
Inet4NetworkInterface | findInterface (const Inet4Address &iaddr) const throw (IOException) |
std::list< Inet4NetworkInterface > | getInterfaces () const throw (IOException) |
Return the IP addresses of all my network interfaces. More... | |
void | close () throw (IOException) |
void | setTimeout (int val) |
Set the timeout for receive(), recv(), and recvfrom() methods. More... | |
void | connect (const std::string &host, int port) throw (UnknownHostException,IOException) |
Datagrams are connectionless, so this doesn't establish a true connection, it just sets the default destination address for the send() calls. More... | |
void | connect (const Inet4Address &addr, int port) throw (IOException) |
Datagrams are connectionless, so this doesn't establish a true connection, it just sets the default destination address for the send() calls. More... | |
void | connect (const SocketAddress &addr) throw (IOException) |
Datagrams are connectionless, so this doesn't establish a true connection, it just sets the default destination address for the send() calls. More... | |
void | bind (const Inet4Address &addr, int port) throw (IOException) |
Bind the DatagramSocket to the specified local address. More... | |
void | bind (const SocketAddress &addr) throw (IOException) |
Bind the DatagramSocket to the specified local address. More... | |
int | getFd () const |
void | receive (DatagramPacketBase &packet) throw (IOException) |
Read a packet from the DatagramSocket. More... | |
void | receive (DatagramPacketBase &packet, Inet4PacketInfo &info, int flags=0) throw (IOException) |
Read a packet from the DatagramSocket. More... | |
void | send (const DatagramPacketBase &packet, int flags=0) throw (IOException) |
size_t | send (const void *buf, size_t len, int flags=0) throw (IOException) |
size_t | send (const struct iovec *iov, int iovcnt, int flags=MSG_NOSIGNAL) throw (IOException) |
size_t | recv (void *buf, size_t len, int flags=0) throw (IOException) |
size_t | recvfrom (void *buf, size_t len, int flags, SocketAddress &from) throw (IOException) |
size_t | sendto (const void *buf, size_t len, int flags, const SocketAddress &to) throw (IOException) |
size_t | sendto (const struct iovec *iov, int iovcnt, int flags, const SocketAddress &to) throw (IOException) |
const SocketAddress & | getLocalSocketAddress () const throw () |
Get local address of this socket. More... | |
int | getLocalPort () const throw () |
Get local port number of this socket. More... | |
void | setNonBlocking (bool val) throw (IOException) |
Do fcntl system call to set O_NONBLOCK file descriptor flag on the socket. More... | |
bool | isNonBlocking () const throw (IOException) |
void | setReceiveBufferSize (int size) throw (IOException) |
int | getReceiveBufferSize () throw (IOException) |
void | setSendBufferSize (int size) throw (IOException) |
int | getSendBufferSize () throw (IOException) |
void | setBroadcastEnable (bool val) throw (IOException) |
bool | getBroadcastEnable () const throw (IOException) |
void | setPktInfo (bool val) throw (IOException) |
Control whether a IP_PKTINFO ancillary message is received with each datagram. More... | |
Protected Attributes | |
SocketImpl | _impl |
A datagram socket to be used for multicasts.
This class provides the default public copy constructors and assignment operators. Objects of this class can be copied and assigned to without restriction. However, because of this, the destructor does not close the socket, so, in general, you should make sure that the socket is closed once at some point.
Usage example:
Note: if the above examples are not working for you, check your firewall settings. They might be blocking multicasts.
|
inline |
Create an unbound multicast socket.
You must bind it to a port if you want to receive packets. If you are sending packets on this MulticastSocket, and do not use getInterfaces() and setInterface() to choose a specific interface, the system sends packets out on the first non-loopback interface that it finds. If a firewall is blocking multicast packets on that interface the packets won't be sent.
|
inline |
Create multicast socket, bind it to a local port.
|
inlineinherited |
Bind the DatagramSocket to the specified local address.
The address should correspond to the address of a local interface. Only packets sent to the given port and interface, by unicast, broadcast or multicast will be received.
Referenced by nidas::core::DatagramSocket::connect(), and nidas::core::DerivedDataReader::run().
|
inlineinherited |
Bind the DatagramSocket to the specified local address.
The address should correspond to the address of a local interface. Only packets sent to the given port and interface, by unicast, broadcast or multicast will be received.
|
inlineinherited |
Referenced by nidas::core::MultipleUDPSockets::close(), nidas::core::UDPSocketIODevice::close(), nidas::core::DatagramSocket::close(), PacketReader::loop(), nidas::core::StatusListener::run(), nidas::core::DerivedDataReader::run(), nidas::core::DSMEngineStat::run(), nidas::util::McSocketListener::run(), nidas::util::McSocketMulticaster< SocketTT >::run(), nidas::util::McSocketListener::~McSocketListener(), and nidas::util::McSocketMulticaster< SocketTT >::~McSocketMulticaster().
|
inlineinherited |
Datagrams are connectionless, so this doesn't establish a true connection, it just sets the default destination address for the send() calls.
Referenced by nidas::core::DatagramSocket::connect(), and nidas::util::McSocketListener::run().
|
inlineinherited |
Datagrams are connectionless, so this doesn't establish a true connection, it just sets the default destination address for the send() calls.
|
inlineinherited |
Datagrams are connectionless, so this doesn't establish a true connection, it just sets the default destination address for the send() calls.
|
inline |
|
inlineinherited |
|
inlineinherited |
Referenced by nidas::core::UDPSocketIODevice::close(), nidas::core::MultipleUDPSockets::getFd(), nidas::core::DatagramSocket::getFd(), nidas::core::UDPSocketIODevice::getReadFd(), nidas::core::UDPSocketIODevice::getWriteFd(), nidas::core::DerivedDataReader::run(), nidas::util::McSocketListener::run(), and nidas::util::McSocketMulticaster< SocketTT >::run().
|
inline |
|
inline |
Return the IP addresses of all my network interfaces.
Referenced by nidas::util::McSocket< SocketT >::getInterfaces(), nidas::util::listMulticastInterfaces(), nidas::core::StatusListener::run(), and nidas::core::DSMServerStat::run().
|
inlineinherited |
Get local port number of this socket.
Referenced by nidas::core::StatusListener::run(), and nidas::util::McSocketMulticaster< SocketTT >::run().
|
inlineinherited |
Get local address of this socket.
Referenced by nidas::core::MultipleUDPSockets::handleChangedSockets(), nidas::core::StatusListener::run(), nidas::core::DerivedDataReader::run(), nidas::core::DSMEngineStat::run(), nidas::util::McSocketListener::run(), and nidas::util::McSocketMulticaster< SocketTT >::run().
|
inline |
|
inlineinherited |
|
inlineinherited |
|
inline |
|
inlineinherited |
Referenced by nidas::core::DatagramSocket::isNonBlocking().
|
inline |
Join a multicast group on all interfaces.
Referenced by nidas::core::UDPSocketIODevice::open(), and nidas::core::StatusListener::run().
|
inline |
Join a multicast group on a given interface.
|
inline |
Leave a multicast group on all interfaces.
|
inline |
Leave a multicast group on a given interface.
|
inlineinherited |
Read a packet from the DatagramSocket.
On return, packet.getLength() will contain the number bytes received, and packet.getSocketAddress() will contain the address of the sender.
Referenced by PacketReader::loop(), nidas::core::DerivedDataReader::run(), nidas::util::McSocketListener::run(), and nidas::util::McSocketMulticaster< SocketTT >::run().
|
inlineinherited |
Read a packet from the DatagramSocket.
On return, packet.getLength() will contain the number bytes received, and packet.getSocketAddress() will contain the address of the sender. info will contain the information on the local and destination addresses of the packet, and the interface it was received on. If setPktInfo(true) has not be set on this socket, then it is set prior to receiving the packet, and then unset after receipt of the packet.
|
inlineinherited |
Referenced by nidas::core::UDPSocketIODevice::read(), and nidas::core::DatagramSocket::read().
|
inlineinherited |
References len.
Referenced by nidas::core::StatusListener::run().
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
References len.
Referenced by nidas::core::StatusThread::sendStatus(), and nidas::core::MultipleUDPSockets::write().
|
inlineinherited |
|
inlineinherited |
|
inline |
Set the interface for a given multicast address.
If you are sending packets on this MulticastSocket, and do not use setInterface() specific interface, the system will send packets out on the first interface that it finds that is capable of MULTICAST. See setInterface(Inet4Address maddr);
If there are no multicast interfaces that are UP, then the system may not choose the loopback interface by default. So doing multicast on a DHCP laptop that isn't connected to the net may give problems.
Referenced by nidas::core::MultipleUDPSockets::addClient(), nidas::core::DSMServerStat::run(), and nidas::util::McSocketMulticaster< SocketTT >::run().
|
inline |
Set the interface for a given multicast address.
This uses the default value of INADDR_ANY for the specific interface, which causes the system to choose what it thinks is the most appropriate interface, typically the first ethernet interface on the system. If you have more than one candidate interface, you can add an entry in the routing table to indicate which you want to use: route add -host 239.0.0.10 dev eth1
|
inline |
Whether to set the IP_MULTICAST_LOOP socket option.
According to "man 7 ip", IP_MULTICAST_LOOP controls "whether sent multicast packets should be looped back to the local sockets." This is the default in Linux in that setting it does not seem to be necessary for a process on a host to receive multicast packets that are sent out on one of its interfaces, providing the multicast reader has joined that interface, and a firewall is not blocking them (a source of frustration!).
Referenced by nidas::core::MultipleUDPSockets::addClient().
|
inlineinherited |
Do fcntl system call to set O_NONBLOCK file descriptor flag on the socket.
val | true=set O_NONBLOCK, false=unset O_NONBLOCK. |
Referenced by nidas::core::DatagramSocket::connect(), nidas::core::McSocketUDP::connect(), nidas::core::McSocketUDP::connected(), and nidas::core::DatagramSocket::setNonBlocking().
|
inlineinherited |
Control whether a IP_PKTINFO ancillary message is received with each datagram.
Only supported on DatagramSockets. The IP_PKTINFO message is converted to an Inet4PacketInfo object which is available via the getInet4PacketInfo() method.
val,: | if true enable the IP_PKTINFO message, if false, disable. |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
Set the timeout for receive(), recv(), and recvfrom() methods.
val | timeout in milliseconds. 0=no timeout (infinite) The receive methods will return IOTimeoutException if an operation times out. |
|
inline |
|
inline |
Creates a datagram socket and binds it to the specified local address.
|
protectedinherited |