Skip to content

Commit

Permalink
Create network client interface class
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz89 committed Dec 25, 2024
1 parent 0e11b1e commit e09f983
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/NetworkClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <Client.h>
#include <WiFiClient.h>

class NetworkClient : public Client {
public:
NetworkClient();
NetworkClient(WiFiClient wifi_client);
virtual ~NetworkClient() = default;

int connect(IPAddress ip, uint16_t port) final;
int connect(const char * host, uint16_t port) final;
int connect(const char * host, uint16_t port, int32_t timeout);
size_t write(uint8_t) final;
size_t write(const uint8_t * buf, size_t size) final;
size_t write(const char * str);
int available() final;
int read() final;
int read(uint8_t * buf, size_t size) final;
int peek() final;
void flush() final;
void stop() final;
uint8_t connected() final;
operator bool() final;

void setCACert(const char * rootCA);
void setCACertBundle(const uint8_t * bundle);
void setInsecure();
bool verify(const char * fingerprint, const char * domain_name);
};
10 changes: 9 additions & 1 deletion src/WebSockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,15 @@
#define WEBSOCKETS_NETWORK_CLASS WiFiClient
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer

#elif(WEBSOCKETS_NETWORK_TYPE != NETWORK_CUSTOM)
#elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_CUSTOM)
#include <NetworkClient.h>
#include <WiFiServer.h>

#define SSL_AXTLS
#define WEBSOCKETS_NETWORK_CLASS NetworkClient
#define WEBSOCKETS_NETWORK_SSL_CLASS NetworkClient
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
#else
#error "no network type selected!"
#endif

Expand Down

0 comments on commit e09f983

Please sign in to comment.