Any way to determine the IP Address a server is listening on?

622 views
Skip to first unread message

Eric Lloyd

unread,
Jul 30, 2013, 11:22:18 AM7/30/13
to webso...@googlegroups.com
Hi all,

I'm trying to present an information dialog to the user in my app that would display the IP Address that the WebSockets++ server is currently listening on. I'm running on windows, and I'm able to get a list of the current IP address(es) on the machine, but in the case of the user having multiple IP Addresses (a wired connection and wireless, for example), is there any way to tell which one the WS++ server is listening on?

Thanks

Peter Thorson

unread,
Jul 30, 2013, 11:53:11 AM7/30/13
to Eric Lloyd, webso...@googlegroups.com
For an endpoint as a whole, what address a WebSocket++ server listens on is determined by which listen overload you use. The overloads that take just a port or a protocol and a port will listen on all interfaces. If you want to listen on a specific interface you can use the either the overload that takes a host and service:


or the overload that takes a fully configured asio endpoint:


More information about how to configure an asio endpoint or what options are valid for the host/service parameters can be found in the Boost Asio documentation.

For a specific already existing connection, you can also retrieve information about the exact local and remove endpoints in use. You can retrieve it manually from the socket using the following:

connection.get_raw_socket().local_endpoint()
connection.get_raw_socket().remote_endpoint()

These return a boost::asio::ip::tcp::endpoint that you can either query directly for a machine readable address/port or output to a stream using <<.

WebSocket++ provides a convenience method for returning a human readable string describing the remote endpoint of a connection using connection::get_remote_endpoint(). This method is independent of the asio transport and will gracefully handle cases where the endpoint is unknown, unavailable, or passed through from an io_stream based connection. As of alpha3 there is no get_local_endpoint() method, but if you would find that useful I can add it.

--
You received this message because you are subscribed to the Google Groups "WebSocket++" group.
To unsubscribe from this group and stop receiving emails from it, send an email to websocketpp...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages