8000 fix #541 allow loop() to be called before begin() · pascalodek/arduinoWebSockets@3f1cedb · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f1cedb

Browse files
committed
fix Links2004#541 allow loop() to be called before begin()
1 parent a71a480 commit 3f1cedb

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/WebSocketsClient.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ WebSocketsClient::WebSocketsClient() {
3131
_client.cIsClient = true;
3232
_client.extraHeaders = WEBSOCKETS_STRING("Origin: file://");
3333
_reconnectInterval = 500;
34+
_port = 0;
35+
_host = "";
3436
}
3537

3638
WebSocketsClient::~WebSocketsClient() {
@@ -148,6 +150,9 @@ void WebSocketsClient::beginSocketIOSSLWithCA(const char * host, uint16_t port,
148150
* called in arduino loop
149151
*/
150152
void WebSocketsClient::loop(void) {
153+
if(_port == 0) {
154+
return;
155+
}
151156
WEBSOCKETS_YIELD();
152157
if(!clientIsConnected(&_client)) {
153158
// do not flood the server

src/WebSocketsClient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ class WebSocketsClient : protected WebSockets {
9191
void enableHeartbeat(uint32_t pingInterval, uint32_t pongTimeout, uint8_t disconnectTimeoutCount);
9292
void disableHeartbeat();
9393

94+
bool isConnected(void);
95+
9496
protected:
9597
String _host;
9698
uint16_t _port;
9799

98-
bool isConnected(void);
99-
100100
#if defined(HAS_SSL)
101101
String _fingerprint;
102102
const char * _CA_cert;

0 commit comments

Comments
 (0)
0