summaryrefslogtreecommitdiffstats
path: root/src/UDPClient/UDPClient.h
diff options
context:
space:
mode:
authorTobias Frust <tobiasfrust@Tobiass-MBP.fritz.box>2016-06-29 19:16:11 +0200
committerTobias Frust <tobiasfrust@Tobiass-MBP.fritz.box>2016-06-29 19:16:11 +0200
commit38b0d8ad024d11fa643934b0c56690b0e57c3e35 (patch)
treef5d53ff1d5c4d1a8efafd5ccdc40d799d7dcc9d5 /src/UDPClient/UDPClient.h
parent5ecc4dde3731724f28d4629f8a563f30bb260617 (diff)
downloadods-38b0d8ad024d11fa643934b0c56690b0e57c3e35.tar.gz
ods-38b0d8ad024d11fa643934b0c56690b0e57c3e35.tar.bz2
ods-38b0d8ad024d11fa643934b0c56690b0e57c3e35.tar.xz
ods-38b0d8ad024d11fa643934b0c56690b0e57c3e35.zip
added UDP-Client and Server classes for data transfer via Ethernet
Diffstat (limited to 'src/UDPClient/UDPClient.h')
-rw-r--r--src/UDPClient/UDPClient.h37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/UDPClient/UDPClient.h b/src/UDPClient/UDPClient.h
index a962fe9..f6cf0d6 100644
--- a/src/UDPClient/UDPClient.h
+++ b/src/UDPClient/UDPClient.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Tobias Frust
+ * http://linux.m2osw.com/c-implementation-udp-clientserver
*
* UDPSender.h
*
@@ -7,9 +7,38 @@
* Author: Tobias Frust
*/
-#ifndef UDPSENDER_H_
-#define UDPSENDER_H_
+#ifndef UDPCLIENT_H_
+#define UDPCLIENT_H_
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <stdexcept>
+#include <cstring>
+class udp_client_server_runtime_error : public std::runtime_error
+{
+public:
+ udp_client_server_runtime_error(const char *w) : std::runtime_error(w) {}
+};
-#endif /* UDPSENDER_H_ */
+
+class UDPClient {
+public:
+ UDPClient(const std::string& addr, int port);
+ ~UDPClient();
+
+ int get_socket() const;
+ int get_port() const;
+ std::string get_addr() const;
+
+ int send(const char *msg, size_t size);
+
+private:
+ int f_socket;
+ int f_port;
+ std::string f_addr;
+ struct addrinfo * f_addrinfo;
+};
+
+#endif /* UDPCLIENT_H_ */