Discussion:
[asio-users] Server and multiple clients
Gonzalo Garramuno
2013-10-28 15:07:46 UTC
Permalink
I have an application that acts as both a server and a client. There
can be multiple clients and the commands to control the application come
both from the server and from the clients. The application works fine
when the server and a single client talk to each other.
My problem is that I do not know how to control the other clients from
one of the clients, as the commanding client does not know about all
other clients. The server knows all clients but it does not know which
of the clients sent the request to distribute to all clients, so it ends
up re-sending the request to the client that sent the command in the
first place.
Hopefully, this all makes sense and there's an easy workaround.
Igor R
2013-10-28 16:11:41 UTC
Permalink
Post by Gonzalo Garramuno
I have an application that acts as both a server and a client. There
can be multiple clients and the commands to control the application come
both from the server and from the clients. The application works fine
when the server and a single client talk to each other.
My problem is that I do not know how to control the other clients from
one of the clients, as the commanding client does not know about all
other clients. The server knows all clients but it does not know which
of the clients sent the request to distribute to all clients, so it ends
up re-sending the request to the client that sent the command in the
first place.
Hopefully, this all makes sense and there's an easy workaround.
Did you try to use socket::remote_endpoint() to identify clients?
Otherwise, you could provide some application-level identification
technique, eg. every client could get a "token" from the server and
send this token on every subsequent call to the server.
Gonzalo Garramuno
2013-10-28 17:27:59 UTC
Permalink
Post by Igor R
Did you try to use socket::remote_endpoint() to identify clients?
No, do you have an example of how to use it? The docs are not very clear.
Igor R
2013-10-28 17:51:58 UTC
Permalink
Post by Gonzalo Garramuno
Post by Igor R
Did you try to use socket::remote_endpoint() to identify clients?
No, do you have an example of how to use it? The docs are not very clear.
http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ip__tcp/endpoint.html
It has address() and port() member function.
Or just see what you get with the following:
std::string s = boost::lexical_cast<std::string>(socket_.remote_endpoint());
Loading...