vendredi 10 mars 2017

vector of boost sockets

I want to design a mechanism with one server and several clients using boost C++ library such that server will have multiple boost sockets connected to each client with a distinct port number. To access these sockets later I want to have an array like structure of these sockets or may be a vector. I have tried to design it like below, but it is giving numerous errors.

std::vector<tcp::socket> sockets_;  
std::vector<tcp::acceptor> acceptors_;

boost::asio::io_service io_service;
tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), port_no));
tcp::socket socket(io_service);
acceptor.accept(socket);
port_no++;
sockets_.push_back(socket);
acceptors_.push_back(acceptor);

I want to access each sockets like acceptor[] and socket[]. Is it possible to do it in C++ or there is any other way, because if the number of client varies I cannot hard code it. Please help if anyone has any prior knowledge or experience to deal with such problems. Thank you,

Aucun commentaire:

Enregistrer un commentaire