bind socket to all ip adresses on the host machine
This commit is contained in:
parent
a210794873
commit
a378205f48
|
@ -45,3 +45,8 @@ add_executable(resolving_dns
|
|||
resolving_dns.cpp
|
||||
src/sdk.h)
|
||||
target_link_libraries(resolving_dns PRIVATE Threads::Threads)
|
||||
|
||||
add_executable(binding_socket_to_an_endpoint
|
||||
binding_socket_to_an_endpoint.cpp
|
||||
src/sdk.h)
|
||||
target_link_libraries(binding_socket_to_an_endpoint PRIVATE Threads::Threads)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#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()
|
||||
{
|
||||
unsigned short port = 3333;
|
||||
asio::ip::tcp::endpoint ep(asio::ip::address_v4::any(), port);
|
||||
asio::io_context io_context;
|
||||
asio::ip::tcp::acceptor acceptor(io_context, ep.protocol());
|
||||
|
||||
sys::error_code ec;
|
||||
|
||||
acceptor.bind(ep, ec);
|
||||
|
||||
if (ec)
|
||||
{
|
||||
cout << "Failed to bind!" << endl;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue