Websocket connection type use

193 views
Skip to first unread message

Ahmed B.Abdallah

unread,
Jan 8, 2020, 3:24:18 AM1/8/20
to WebSocket++

Hello,

 

I'm using the websocket endpoint library in a C++ application which is running under an embedded client system. My websocket server is running through different system.

 

My embedded system is using several physical connection types such as Wifi, Ethernet, GPRS to connect to the server.

 

How can I configure my websocket client to use a specific physical connection type (wifi or ethernet)?

 

Thank you for your feedback.

 

Regards

Brian Hamon

unread,
Jan 8, 2020, 6:49:37 PM1/8/20
to Ahmed B.Abdallah, WebSocket++
You should be able to bind to any IPv4 or IPv6 interface available on your system. To see what addresses are available, enter the shell command `ip a`.

Choose the IP address of the interface that is assigned to the physical connection device you want your websockets server to listen on.

Typically, a websocketpp will implement a server with a member named `m_server`. When the server's `run` method, you should see a call like this:

    m_server.listen(port);

This results in a call to `void websocketpp::transport::asio::endpoint<config>::listen(uint16_t port)`

There is another overload available which takes two strings:

    void listen(std::string const & host, std::string const & service, lib::error_code & ec)

The documentation for this overload is:

    /// Set up endpoint for listening on a host and service (exception free)
    /**
     * Bind the internal acceptor using the given host and service. More details
     * about what host and service can be are available in the Asio
     * documentation for ip::basic_resolver_query::basic_resolver_query's
     * constructors.
     *
     * The endpoint must have been initialized by calling init_asio before
     * listening.
     *
     * @param host A string identifying a location. May be a descriptive name or
     * a numeric address string.
     * @param service A string identifying the requested service. This may be a
     * descriptive name or a numeric string corresponding to a port number.
     * @param ec Set to indicate what error occurred, if any.
     */

So, suppose you want to listen on your Wifi device. You determine by examining your system configuration that the Wifi interface is assigned the IP address 10.1.2.3, for example. Then you could listen on port 9002 of that interface by changing your server's run method to start the listen as follows:

std::error_code ec;
m_server.listen("10.1.2.3", "9002", ec);

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/websocketpp/1f3bd4d0-5e60-4da9-9e5e-13faab8ae9b6%40googlegroups.com.

Ahmed B.Abdallah

unread,
Jan 9, 2020, 6:33:51 AM1/9/20
to WebSocket++
Thank you for your feedback Brian.

I'm not actually able to change the settings of my server side. So my concern, is that from client side how can I specify the physical connection to use.

Typically, the server is always running on a specific already known connection type and from client side I have multiple connections.

My question, is that from client side how can I set the approriate source address or the connection type to be used  in order to establish the connection with this server ?

Regards
To unsubscribe from this group and stop receiving emails from it, send an email to webso...@googlegroups.com.

Ahmed B.Abdallah

unread,
Jan 10, 2020, 8:39:18 AM1/10/20
to WebSocket++
Note that using the following instructions:

asio::error_code er;
asio::ip::address address = m_endpoint.get_local_endpoint(er).address();
std::string s = address.to_string();

I'm getting null value of address.
Reply all
Reply to author
Forward
0 new messages