Warm tip: This article is reproduced from serverfault.com, please click

Getting server IP within wasm application

发布于 2020-12-15 07:20:53

I use C++ and Qt 5.15.x. I've built WebAssembly version of my desktop application. The application is loaded using URL like "http://192.168.21.55:5555" (intranet application). I'd like to extract server IP address within WebAssembly application. How can I achieve it?

Questioner
ilya
Viewed
0
ilya 2021-01-13 17:59:14

There is no solution for ip extraction, but I've found the way to get host and port (host is equal to ip in my case).

#include <emscripten/val.h>
emscripten::val location = emscripten::val::global("location");
auto host = QString::fromStdString(location["host"].as<std::string>());
auto port = QString::fromStdString(location["port"].as<std::string>());