On Tencent cloud Server to do. I used 0.0.0.0 to bind the listening port, and an error occurred when running. If I use the ip found in localhost or ifconfig, there will be no error. Because ifconfig contains the intranet address. I want it to be accessible from the public network.
The following is the log where the error occurred:
E |2023-09-15 17:19:37 1694769577143334| [oatpp::network::tcp::server::ConnectionProvider::instantiateServer()]:Error. Couldn't bind. Cannot assign requested address
terminate called after throwing an instance of 'std::runtime_error'
what(): [oatpp::network::tcp::server::ConnectionProvider::instantiateServer()]: Error. Couldn't bind Cannot assign requested address
Related code:
void run() {
/* Create Router for HTTP requests routing */
auto router = oatpp::web::server::HttpRouter::createShared();
/* Route GET - "/hello" requests to Handler */
router -> route("GET", "/hello", std::make_shared<Handler>());
router -> route("GET", "/huang", std::make_shared<Huang>());
/* Create HTTP connection handler with router */
auto connectionHandler = oatpp::web::server::HttpConnectionHandler::createShared(router);
/* Create TCP connection provider */
auto connectionProvider = oatpp::network::tcp::server::ConnectionProvider::createShared({"0.0.0.0", 8000, oatpp::network::Address::IP_4});
/* Create server which takes provided TCP connections and passes them to HTTP connection handler */
oatpp::network::Server server(connectionProvider, connectionHandler);
/* Priny info about server port */
OATPP_LOGI("MyApp", "Server running on port %s", connectionProvider->getProperty("port").getData());
/* Run server */
server.run();
}
output of ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.12.8 netmask 255.255.252.0 broadcast 10.0.15.255
inet6 fe80::5054:ff:fe9b:8c05 prefixlen 64 scopeid 0x20<link>
ether 52:54:00:9b:8c:05 txqueuelen 1000 (Ethernet)
RX packets 83825 bytes 64075575 (64.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 57376 bytes 24188720 (24.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (local loopback)
RX packets 24642 bytes 6743792 (6.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 24642 bytes 6743792 (6.7 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
What should I do can listen public network?