/**
* Relational pipes
* Copyright © 2022 František Kučera (Frantovo.cz, GlobalCode.info)
*
* 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, version 3 of the License.
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <cstring>
#include <unistd.h>
#include <stdexcept>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
namespace relpipe {
namespace out {
namespace socket {
class Socket {
private:
public:
virtual ~Socket() {
}
void send(const std::string& message) {
struct sockaddr_in a;
memset((char *) &a, 0, sizeof (a));
a.sin_family = AF_INET;
a.sin_addr.s_addr = inet_addr("127.0.0.1"); // TODO: use getaddrinfo() instead (because of error -1 = 255.255.255.255)
a.sin_port = htons(1234);
int s = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
sendto(s, message.c_str(), message.size(), 0, (sockaddr*) & a, sizeof (a));
close(s);
// TODO: send message
}
// virtual const std::string receive();
};
}
}
}