Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get client's ip and port? #422

Closed
q191201771 opened this issue Apr 22, 2015 · 3 comments
Closed

how to get client's ip and port? #422

q191201771 opened this issue Apr 22, 2015 · 3 comments

Comments

@q191201771
Copy link

as a server,how to get client's ip and port?
is there any convenient interface in connection_hdl or anywhere?

@zaphoyd
Copy link
Owner

zaphoyd commented Apr 22, 2015

connection::get_remote_endpoint() will return a human readable address+port as a string for the connected client (in the case of a server) or the connected server (in the case of a client). This should work independently of the transport policy in use (though some transport policies may provide more or less information than others)

An alternative, that works only with the asio transport, you can query the remote endpoint directly. connection::get_raw_socket() will return a boost::asio::ip::tcp::socket & which you can then query for all of the various machine or human readable details about the local and remote endpoint. See http://stackoverflow.com/questions/5352757/boost-asio-socket-how-to-get-ip-port-adress-of-connection and http://stackoverflow.com/questions/601763/how-to-get-ip-addresss-of-boostasioiptcpsocket for some details on extracting information from the asio socket.

@q191201771
Copy link
Author

thx a lot

@HimanshuNandu
Copy link

Can I also get the windows username from the connected client socket connection_hdl ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants