diff --git a/demo/windows_sender/NetworkSender.cpp b/demo/windows_sender/NetworkSender.cpp index 19656ba..cefab72 100644 --- a/demo/windows_sender/NetworkSender.cpp +++ b/demo/windows_sender/NetworkSender.cpp @@ -20,7 +20,7 @@ NetworkSender::~NetworkSender() { WSACleanup(); } -bool NetworkSender::Initialize(const std::string& ip, int port) { +bool NetworkSender::Initialize(const std::vector& ips, int port) { socket_ = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (socket_ == INVALID_SOCKET) return false; @@ -28,11 +28,16 @@ bool NetworkSender::Initialize(const std::string& ip, int port) { int sndBuf = 1024 * 1024; // 1MB setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, (char*)&sndBuf, sizeof(sndBuf)); - destAddr_.sin_family = AF_INET; - destAddr_.sin_port = htons(port); - inet_pton(AF_INET, ip.c_str(), &destAddr_.sin_addr); + destAddrs_.clear(); + for (const auto& ip : ips) { + sockaddr_in addr = {}; + addr.sin_family = AF_INET; + addr.sin_port = htons(port); + inet_pton(AF_INET, ip.c_str(), &addr.sin_addr); + destAddrs_.push_back(addr); + } - return true; + return !destAddrs_.empty(); } bool NetworkSender::SendFrame(const std::vector& data, uint64_t timestamp, int width, int height, bool isKeyFrame) { @@ -75,10 +80,12 @@ bool NetworkSender::SendFrame(const std::vector& data, uint64_t timesta memcpy(packet.data(), &transHeader, HEADER_SIZE); memcpy(packet.data() + HEADER_SIZE, buffer.data() + offset, chunkSize); - int sent = sendto(socket_, (const char*)packet.data(), (int)packet.size(), 0, (sockaddr*)&destAddr_, sizeof(destAddr_)); - if (sent < 0) { - // std::cerr << "Send failed" << std::endl; - // Continue sending other fragments anyway + for (const auto& addr : destAddrs_) { + int sent = sendto(socket_, (const char*)packet.data(), (int)packet.size(), 0, (sockaddr*)&addr, sizeof(addr)); + if (sent < 0) { + // std::cerr << "Send failed" << std::endl; + // Continue sending other fragments anyway + } } } diff --git a/demo/windows_sender/NetworkSender.h b/demo/windows_sender/NetworkSender.h index b83952b..68d7aee 100644 --- a/demo/windows_sender/NetworkSender.h +++ b/demo/windows_sender/NetworkSender.h @@ -21,10 +21,10 @@ public: NetworkSender(); ~NetworkSender(); - bool Initialize(const std::string& ip, int port); + bool Initialize(const std::vector& ips, int port); bool SendFrame(const std::vector& data, uint64_t timestamp, int width, int height, bool isKeyFrame); private: SOCKET socket_ = INVALID_SOCKET; - sockaddr_in destAddr_; + std::vector destAddrs_; }; diff --git a/demo/windows_sender/main.cpp b/demo/windows_sender/main.cpp index 24b97d6..a4a4b86 100644 --- a/demo/windows_sender/main.cpp +++ b/demo/windows_sender/main.cpp @@ -2,21 +2,37 @@ #include "ScreenCapture.h" #include "VideoEncoder.h" #include +#include +#include #include #include #include int main(int argc, char* argv[]) { - std::string ip = "127.0.0.1"; + std::string ipStr = "127.0.0.1"; int port = 8888; std::string outputFileName = ""; - if (argc > 1) ip = argv[1]; + if (argc > 1) ipStr = argv[1]; if (argc > 2) port = std::stoi(argv[2]); if (argc > 3) outputFileName = argv[3]; + // Parse IPs + std::vector ips; + std::stringstream ss(ipStr); + std::string item; + while (std::getline(ss, item, ',')) { + // Trim spaces might be good but let's assume no spaces for simplicity or user should handle + if (!item.empty()) { + ips.push_back(item); + } + } + if (ips.empty()) ips.push_back("127.0.0.1"); + std::cout << "Starting Windows Sender Demo..." << std::endl; - std::cout << "Target: " << ip << ":" << port << std::endl; + std::cout << "Targets: "; + for (const auto& ip : ips) std::cout << ip << " "; + std::cout << ", Port: " << port << std::endl; if (!outputFileName.empty()) { std::cout << "Output File: " << outputFileName << std::endl; } @@ -60,7 +76,7 @@ int main(int argc, char* argv[]) { } NetworkSender sender; - if (!sender.Initialize(ip, port)) { + if (!sender.Initialize(ips, port)) { std::cerr << "Failed to initialize Network Sender" << std::endl; return 1; }