diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index c67b706..967bc9d 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -31,6 +31,8 @@ WebSocketsClient::WebSocketsClient() { _client.cIsClient = true; _client.extraHeaders = WEBSOCKETS_STRING("Origin: file://"); _reconnectInterval = 500; + _port = 0; + _host = ""; } WebSocketsClient::~WebSocketsClient() { @@ -148,6 +150,9 @@ void WebSocketsClient::beginSocketIOSSLWithCA(const char * host, uint16_t port, * called in arduino loop */ void WebSocketsClient::loop(void) { + if(_port == 0) { + return; + } WEBSOCKETS_YIELD(); if(!clientIsConnected(&_client)) { // do not flood the server diff --git a/src/WebSocketsClient.h b/src/WebSocketsClient.h index ed3f630..0f51c94 100644 --- a/src/WebSocketsClient.h +++ b/src/WebSocketsClient.h @@ -91,12 +91,12 @@ class WebSocketsClient : protected WebSockets { void enableHeartbeat(uint32_t pingInterval, uint32_t pongTimeout, uint8_t disconnectTimeoutCount); void disableHeartbeat(); + bool isConnected(void); + protected: String _host; uint16_t _port; - bool isConnected(void); - #if defined(HAS_SSL) String _fingerprint; const char * _CA_cert;