active socket
This commit is contained in:
parent
032dc6db56
commit
a210794873
|
@ -33,11 +33,15 @@ target_link_libraries(server_endpoint PRIVATE Threads::Threads)
|
||||||
|
|
||||||
add_executable(active_socket
|
add_executable(active_socket
|
||||||
active_socket.cpp
|
active_socket.cpp
|
||||||
src/sdk.h
|
src/sdk.h)
|
||||||
passive_socket.cpp)
|
|
||||||
target_link_libraries(active_socket PRIVATE Threads::Threads)
|
target_link_libraries(active_socket PRIVATE Threads::Threads)
|
||||||
|
|
||||||
add_executable(passive_socket
|
add_executable(passive_socket
|
||||||
passive_socket.cpp
|
passive_socket.cpp
|
||||||
src/sdk.h)
|
src/sdk.h)
|
||||||
target_link_libraries(passive_socket PRIVATE Threads::Threads)
|
target_link_libraries(passive_socket PRIVATE Threads::Threads)
|
||||||
|
|
||||||
|
add_executable(resolving_dns
|
||||||
|
resolving_dns.cpp
|
||||||
|
src/sdk.h)
|
||||||
|
target_link_libraries(resolving_dns PRIVATE Threads::Threads)
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
#include "src/sdk.h"
|
||||||
|
#include <boost/asio.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace boost;
|
||||||
|
namespace sys = boost::system;
|
||||||
|
namespace net = boost::asio;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
string host = "yandex.ru"s;
|
||||||
|
string port = "8080";
|
||||||
|
|
||||||
|
net::io_context ios;
|
||||||
|
net::ip::tcp::resolver::query resolver_query(
|
||||||
|
host, port, net::ip::tcp::resolver::query::numeric_service
|
||||||
|
);
|
||||||
|
|
||||||
|
net::ip::tcp::resolver resolver(ios);
|
||||||
|
|
||||||
|
sys::error_code ec;
|
||||||
|
|
||||||
|
net::ip::tcp::resolver::iterator iter = resolver.resolve(resolver_query, ec);
|
||||||
|
|
||||||
|
if (ec)
|
||||||
|
{
|
||||||
|
cout << "Error!" << endl;
|
||||||
|
|
||||||
|
return ec.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Your ip is: "s << iter->endpoint().address().to_string() << endl;
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Loading…
Reference in New Issue