I am trying to understand the concept of network programming using sockets.
As I understand there is a parallelity to a phone conversation, the
- Endpoint would be the phone number, the
- Socket the phone and the
- Acceptor is the one picking up the phone.
So then, the
Socket is bound to the endpoint (the phone is connected to the plug) and the
Acceptor gets access to the socket and a handler (a person is put next to the phone and gets a task what to do if someone calls)
If that is a valid visualization, then why can you bind the acceptor directly to an endpoint and give the acceptor the socket afterwards? Or is the above plainly wrong?
tcp::endpoint ep(boost::asio::ip::address::from_string("192.168.XXX.XXX"), portNumber);
tcp::acceptor a(io_service);
tcp::socket s(io_service);
a.open(ep.protocoll());
a.bind(endpoint);
a.listen(boost::asio::socket_base::max_connections);
a.async_accept(s, myHandler);