jsocketpp 1.0
A cross-platform C++20 socket library.
Loading...
Searching...
No Matches
MulticastSocket.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "DatagramSocket.hpp"
9#include "common.hpp"
10
11#include <string>
12
13namespace jsocketpp
14{
15
69{
70 public:
80 explicit MulticastSocket(Port port = 0, std::size_t bufferSize = 2048);
81
92 void joinGroup(const std::string& groupAddr, const std::string& iface = "");
93
101 void leaveGroup(const std::string& groupAddr, const std::string& iface = "");
102
112 void setMulticastInterface(const std::string& iface);
113
124 std::string getMulticastInterface() const { return _currentInterface; }
125
141 void setTimeToLive(int ttl);
142
156 int getTimeToLive() const { return _ttl; }
157
165 void setLoopbackMode(bool enable);
166
176 int getLoopbackMode() const { return _loopbackEnabled; }
177
182 std::string getCurrentGroup() const;
183
184 private:
185 std::string _currentGroup{};
186 std::string _currentInterface{};
187
199 int _ttl = 1;
200
210 bool _loopbackEnabled = true;
211};
212
213} // namespace jsocketpp
UDP datagram socket abstraction for jsocketpp.
DatagramSocket(Port port, std::size_t bufferSize=2048)
Constructs a UDP socket optionally bound to a local port.
Definition DatagramSocket.cpp:6
std::string getCurrentGroup() const
Returns the last multicast group joined (for reference/debug).
Definition MulticastSocket.cpp:470
std::string _currentInterface
Interface used for multicast.
Definition MulticastSocket.hpp:186
MulticastSocket(Port port=0, std::size_t bufferSize=2048)
Constructs a multicast socket optionally bound to a local port and buffer size.
Definition MulticastSocket.cpp:5
void setTimeToLive(int ttl)
Set the time-to-live (TTL) for outgoing multicast packets.
Definition MulticastSocket.cpp:393
std::string _currentGroup
Last joined multicast group address.
Definition MulticastSocket.hpp:185
std::string getMulticastInterface() const
Gets the currently set interface for outgoing multicast packets.
Definition MulticastSocket.hpp:124
void setLoopbackMode(bool enable)
Enables or disables multicast loopback.
Definition MulticastSocket.cpp:428
int _ttl
Default TTL (Time To Live) value for multicast packets.
Definition MulticastSocket.hpp:199
void joinGroup(const std::string &groupAddr, const std::string &iface="")
Joins a multicast group.
Definition MulticastSocket.cpp:11
int getTimeToLive() const
Get the current time-to-live (TTL) value for outgoing multicast packets.
Definition MulticastSocket.hpp:156
int getLoopbackMode() const
Get the current multicast loopback mode setting.
Definition MulticastSocket.hpp:176
void setMulticastInterface(const std::string &iface)
Sets the default interface for outgoing multicast packets.
Definition MulticastSocket.cpp:317
void leaveGroup(const std::string &groupAddr, const std::string &iface="")
Leaves a multicast group.
Definition MulticastSocket.cpp:166
bool _loopbackEnabled
Controls whether multicast packets loop back to the sending host.
Definition MulticastSocket.hpp:210
Common platform and utility includes for jsocketpp.
std::uint16_t Port
Type alias representing a TCP or UDP port number (1–65535).
Definition common.hpp:315
A C++ socket library providing Java-style networking interfaces.
Definition BufferView.hpp:13