-
Notifications
You must be signed in to change notification settings - Fork 0
/
RemoteNotifyBroadcast.h
62 lines (57 loc) · 1.85 KB
/
RemoteNotifyBroadcast.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @file RemoteNotifyBroadcast.h
* @brief Broadcast for sending notifications to `RemoteNotify:Receive`
*
* @copyright Copyright (C) 2021 Conor Begley
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifndef REMOTENOTIFYBROADCAST_H_
#define REMOTENOTIFYBROADCAST_H_
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <unistd.h>
#include <cstring>
#include <iostream>
namespace RemoteNotify {
/**
* @brief A Broadcast to send messages to `RemoteNotify::Receive`
*
*/
class Broadcast {
private:
int broadcast_fd; ///< Socket which the Broadcast is bound to
struct sockaddr_in address; ///< Broadcast address structure
char* target_ip; ///< Broadcast IP address
public:
/**
* @brief Constructor for `RemoteNotify::Broadcast`
*
* @param port Port number to listen on (default is 121121)
* @param ip Broadcast address (default is 255.255.255.255)
*/
explicit Broadcast(int port = 121121,
char* ip = const_cast<char*>("255.255.255.255"));
~Broadcast();
/**
* @brief Broadcasts message to ip
* @param msg The message to be sent
*/
void sendMessage(std::string msg);
};
} // namespace RemoteNotify
#endif // REMOTENOTIFYBROADCAST_H_