diff --git a/utilities/TCPBeacons_CPP/Application/TCPBeaconsClient.exe b/utilities/TCPBeacons_CPP/Application/TCPBeaconsClient.exe index 3d232ab..56ab7a9 100644 Binary files a/utilities/TCPBeacons_CPP/Application/TCPBeaconsClient.exe and b/utilities/TCPBeacons_CPP/Application/TCPBeaconsClient.exe differ diff --git a/utilities/TCPBeacons_CPP/Application/TCPBeaconsServer.exe b/utilities/TCPBeacons_CPP/Application/TCPBeaconsServer.exe index d0abdd6..2b0aa59 100644 Binary files a/utilities/TCPBeacons_CPP/Application/TCPBeaconsServer.exe and b/utilities/TCPBeacons_CPP/Application/TCPBeaconsServer.exe differ diff --git a/utilities/TCPBeacons_CPP/TCPBeacons/main.cpp b/utilities/TCPBeacons_CPP/TCPBeacons/main.cpp index 2950013..32319f5 100644 --- a/utilities/TCPBeacons_CPP/TCPBeacons/main.cpp +++ b/utilities/TCPBeacons_CPP/TCPBeacons/main.cpp @@ -84,9 +84,6 @@ int __cdecl main(int argc, char* argv[]) } - - - // >>>>>>> TCP/IP HANDLER <<<<<<< std::string ipAddress = "127.0.0.1"; // ip of the server @@ -131,8 +128,7 @@ int __cdecl main(int argc, char* argv[]) } - - // Send Beacons to TCP server then receive the beacons from server and echo out + // Send Beacons to TCP server then echo the beacons from server bool exit = false; char buf[4096]; @@ -167,12 +163,7 @@ int __cdecl main(int argc, char* argv[]) } - - std::cout << "Stopping TCP/IP Connection to the Server." << std::endl; closesocket(sock_); WSACleanup(); - - - std::this_thread::sleep_for(std::chrono::seconds(5)); } \ No newline at end of file diff --git a/utilities/TCPBeacons_CPP/TCPBeaconsClient.exe b/utilities/TCPBeacons_CPP/TCPBeaconsClient.exe new file mode 100644 index 0000000..227ddcf Binary files /dev/null and b/utilities/TCPBeacons_CPP/TCPBeaconsClient.exe differ diff --git a/utilities/TCPBeacons_CPP/TCPBeaconsServer/main.cpp b/utilities/TCPBeacons_CPP/TCPBeaconsServer/main.cpp index aa44c32..00ace7d 100644 --- a/utilities/TCPBeacons_CPP/TCPBeaconsServer/main.cpp +++ b/utilities/TCPBeacons_CPP/TCPBeaconsServer/main.cpp @@ -18,11 +18,10 @@ #define LISTENING_PORT 1901 + void sendBeacons(SOCKET sock_, std::vector beacons, int innerDelay, int outerDelay) { bool exit = false; - char buf[4096]; - while (exit == false) { for (std::size_t i = 0; i < beacons.size(); i++) @@ -32,20 +31,48 @@ void sendBeacons(SOCKET sock_, std::vector beacons, int innerDelay, // send beacons to client send(sock_, beacons[i].c_str(), beacons[i].size() + 1, 0); + // exit when user hit esc + if (GetAsyncKeyState(VK_ESCAPE)) { + exit = true; + break; + } + Sleep(innerDelay); + + } + } + + Sleep(outerDelay); + } + +} + +void receiveBeacons(SOCKET sock_, std::vector beacons, int innerDelay, int outerDelay) +{ + bool exit = false; + char buf[4096]; + + while (exit == false) + { + for (std::size_t i = 0; i < beacons.size(); i++) + { + if (sock_ != SOCKET_ERROR) + { + // echo beacons sent from client ZeroMemory(buf, 4096); int byteRecv = recv(sock_, buf, 4096, 0); - if (byteRecv == SOCKET_ERROR) - { - std::cerr << "Error in recv(). Quitting" << std::endl; - break; - } if (byteRecv == 0) { std::cout << "Client disconnected" << std::endl; + if (byteRecv == SOCKET_ERROR) + { + std::cerr << "Error in recv(). Quitting" << std::endl; + break; + } + break; } - + // echo the message std::cout << std::string(buf, 0, byteRecv) << std::endl; @@ -58,9 +85,10 @@ void sendBeacons(SOCKET sock_, std::vector beacons, int innerDelay, } } + Sleep(outerDelay); } - + } int __cdecl main(int argc, char* argv[]) @@ -222,21 +250,23 @@ int __cdecl main(int argc, char* argv[]) // Send beacons to clients std::cout << std::endl; - std::cout << "Sending TCP/IP beacons to " << host << "starts now!" << std::endl; + std::cout << "Sending TCP/IP beacons to " << host << "! Start now!" << std::endl; bool exit = false; char buf[4096]; // Server sends beacons to clients through multi threads - std::thread th(sendBeacons, clientSocket, beacons, innerDelay, outerDelay); - th.detach(); + std::thread sendThread(sendBeacons, clientSocket, beacons, innerDelay, outerDelay); + sendThread.detach(); + std::thread recvThread(receiveBeacons, clientSocket, beacons, innerDelay, outerDelay); + recvThread.detach(); } } + } - // Cleanup winsock WSACleanup(); system("pause");