gilmaimon / ArduinoWebsockets

A library for writing modern websockets applications with Arduino (ESP8266 and ESP32)
GNU General Public License v3.0
482 stars 97 forks source link

How to export the _client object? #100

Closed DynamicLoader closed 3 years ago

DynamicLoader commented 3 years ago

The library is so good!

As you know,Websocket(S) protocol does not support authentication.So I have to use HTTP(S) basic authentication.

In that case,I need to pass a TCP client object to HTTPClient object.

And init SSL will take a while before we can use HTTPS or WSS. In order to faster the connection,I want to export the _client object from the websocket object so that I could just connect once to the server and start a HTTP request,and then reuse the connection for websocket whithout re-init SSL.

But I didn't find any function in the library to do this( _client is private).

I also found a function called WebsocketsClient(std::shared_ptr<network::TcpClient> client) to init websocket object with a client object,but I don't know how to use it.

Please give me some suggestions.

Thanks!

gilmaimon commented 3 years ago

Hi :)

I'm not completely sure what you are trying to do, but (as you already started to do) you can go in and change the library as you want for your needs. The function WebsocketsClient(std::shared_ptr<network::TcpClient> client) is a constructor. I assume you know what constructors are, if not, consider reading about C++ Constructors...

You can look at esp32_tcp.hpp and esp8266_tcp.hpp for the esp32/esp8266 clients implementation. For example, look at

typedef GenericEspTcpClient<WiFiClient> Esp8266TcpClient;

This means you can use Esp8266TcpClient, and pass the c'tor the actual WiFiClient (see generic_esp_clients.hpp for full detail on GenericEspTcpClient`

Good luck! Gil.

DynamicLoader commented 3 years ago

I will have a try.Thanks!