diff options
author | Tobias Frust <tobiasfrust@Tobiass-MacBook-Pro.fritz.box> | 2016-06-29 21:44:58 +0200 |
---|---|---|
committer | Tobias Frust <tobiasfrust@Tobiass-MacBook-Pro.fritz.box> | 2016-06-29 21:44:58 +0200 |
commit | 1dc95b4eed7974549ef43a87e0777aa343b30fd4 (patch) | |
tree | c61eaa825e4b873354318f1fdc776fa53b2d303e /src | |
parent | 38b0d8ad024d11fa643934b0c56690b0e57c3e35 (diff) | |
download | ods-1dc95b4eed7974549ef43a87e0777aa343b30fd4.tar.gz ods-1dc95b4eed7974549ef43a87e0777aa343b30fd4.tar.bz2 ods-1dc95b4eed7974549ef43a87e0777aa343b30fd4.tar.xz ods-1dc95b4eed7974549ef43a87e0777aa343b30fd4.zip |
added client and server executable for testing simple udp packet transfer
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 10 | ||||
-rw-r--r-- | src/UDPServer/UDPServer.cpp | 10 | ||||
-rw-r--r-- | src/UDPServer/UDPServer.h | 8 | ||||
-rw-r--r-- | src/main.cpp | 11 | ||||
-rw-r--r-- | src/main_server.cpp | 28 |
5 files changed, 61 insertions, 6 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 746b901..80196d9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,11 +31,17 @@ include_directories( ${BOOST_INCLUDE_DIRS} ) -set(SOURCES +set(SOURCES_CLIENT "${CMAKE_SOURCE_DIR}/UDPClient/UDPClient.cpp" "${CMAKE_SOURCE_DIR}/main.cpp" ) -add_executable(onlineDetectorSimulator ${SOURCES}) +set(SOURCES_SERVER + "${CMAKE_SOURCE_DIR}/UDPServer/UDPServer.cpp" + "${CMAKE_SOURCE_DIR}/main_server.cpp" +) + +add_executable(onlineDetectorSimulatorServer ${SOURCES_SERVER}) +add_executable(onlineDetectorSimulatorClient ${SOURCES_CLIENT}) diff --git a/src/UDPServer/UDPServer.cpp b/src/UDPServer/UDPServer.cpp index cd36647..854835a 100644 --- a/src/UDPServer/UDPServer.cpp +++ b/src/UDPServer/UDPServer.cpp @@ -41,6 +41,16 @@ * \param[in] addr The address we receive on. * \param[in] port The port we receive from. */ + +#include "UDPServer.h" + + #include <string.h> + #include <unistd.h> + + #ifndef SOCK_CLOEXEC + #define SOCK_CLOEXEC 0 + #endif + UDPServer::UDPServer(const std::string& addr, int port) : f_port(port) , f_addr(addr) diff --git a/src/UDPServer/UDPServer.h b/src/UDPServer/UDPServer.h index 7eef796..22f33b3 100644 --- a/src/UDPServer/UDPServer.h +++ b/src/UDPServer/UDPServer.h @@ -14,7 +14,13 @@ #include <sys/socket.h> #include <netdb.h> #include <stdexcept> -#include <string> +#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) {} +}; class UDPServer { diff --git a/src/main.cpp b/src/main.cpp index 2ff08b2..6898a09 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,10 +12,15 @@ int main (int argc, char *argv[]){ UDPClient client = UDPClient(address, port); - std::string msg = "test"; - std::size_t length{msg.size()}; + std::size_t length{8008}; - client.send(msg.c_str(), length); + char buf[length]; + for(auto i = 0; i < length; i++){ + *(buf+i) = i%128; + } + + + client.send(buf, length); return 0; diff --git a/src/main_server.cpp b/src/main_server.cpp new file mode 100644 index 0000000..b90de52 --- /dev/null +++ b/src/main_server.cpp @@ -0,0 +1,28 @@ +#include "UDPServer/UDPServer.h" + +#include <iostream> +#include <string> + +int main (int argc, char *argv[]){ + + std::cout << "Receiving UDP packages: " << std::endl; + + std::string address = "localhost"; + int port = 1234; + + UDPServer server = UDPServer(address, port); + + std::size_t length{8000}; + + char buf[length]; + + server.recv(buf, length); + + for(auto i = 0; i < length; i++){ + printf("%c", buf[i]); + } + printf("\n"); + + return 0; + +} |