#include #include #include #include #include #include namespace beast = boost::beast; namespace websocket = beast::websocket; namespace net = boost::asio; using tcp = boost::asio::ip::tcp; std::tuple parseURI(const std::string& uri) { std::regex uriRegex(R"(^ws://([^:/]+):(\d+)(/.+)$)"); std::smatch match; if (std::regex_match(uri, match, uriRegex)) { return std::make_tuple(match[1].str(), match[2].str(), match[3].str()); } else { throw std::invalid_argument("Nieprawidłowe URI"); } } int main() { std::string uri = "ws://172.24.0.3:3333"; std::cout << "Dostarczone URI: " << uri << std::endl; try { auto uriParts = parseURI(uri); std::string host, port, endpoint; std::tie(host, port, endpoint) = uriParts; net::io_context io_context; // Utwórz obiekt WebSocket websocket::stream ws(io_context); // Połącz z serwerem WebSocket tcp::resolver resolver(io_context); auto endpoints = resolver.resolve(host, port); net::connect(ws.next_layer(), endpoints); // Wysyłanie danych na serwer WebSocket ws.handshake(host, endpoint); } catch (const std::exception& e) { std::cerr << "Błąd: " << e.what() << std::endl; return EXIT_FAILURE; } return EXIT_SUCCESS; }